2

I am trying to create a batch file that needs to be passed a path and has operations in it that requires elevation (I use mklink in it).

Here is how to recreate the problem.

  1. Make a .bat file that just contains pause
  2. Make a shortcut to that batch file.
  3. Create 2 folders, C:\ThisWillWork and C:\This Will Fail
  4. Try dragging each folder on to the shortcut. Both should work.
  5. Change the shortcut settings and check in the advanced options options that it requires administrator privileges.
  6. Try dragging each folder again, C:\ThisWillWork will behave the same but C:\This Will Fail will flash the command prompt and immedatly close itself.

This is being done on Windows 7 64-bit.

What can I do to accomplish my goal? Is there a way to allow me to use mklink without elevation? Do I need to switch from using windows batch files to something else (powershell maybe)? What else can I use to be able to write a script to delete a folder then recreate it with as a directory symlink to the folder I dropped on it?

1 Answers1

3

Try creating a shortcut as

%Windir%\System32\cmd.exe /C C:\BIN\batchfile.bat 

If that doesn't solve it on its own try the following.

To resolve this problem, change the Start in value in the Command Prompt Properties dialog box or in the Notepad Properties dialog box.

To do so, follow these steps:
Click Start, point to All Programs, and then point to Accessories.
Right-click Command Prompt or Notepad, and then click Properties.
In the Start in box, change the value from %HOMEDRIVE%%HOMEPATH% to a system-wide value such as %WINDIR%.
Click OK.

See http://support.microsoft.com/kb/832434 for full details.

If you to see more of what is going on you with your original method, you can open a command prompt as admin and type

%windir%\System32\cmd.exe /C "C:\bin\batchfile.bat" "C:\THIS WILL FAIL" 

This will give an error without loading the batchfile as it fails some command line parsing.

sgmoore
  • 6,599