runas batch file

  • Thread starter Thread starter vani
  • Start date Start date
Add pause right to the end of your install.cmd
e.g :

@echo off
echo Hello World...
pause
 
Let's have a look at the batch file!
These are the batch files(I've rearanged the order so now the user starts
install.cmd by double click, and then from install.cmd runas starts 1.cmd):

-install.cmd contents:
runas /user:administrator 1.cmd


-1.cmd contents:
copy /y aCalendar.gms "C:\Program Files\Corel\CorelDRAW Graphics Suite
X4\Draw\GMS\"
copy /y aCalendar.gms "C:\Program Files\Corel\CorelDRAW Graphics Suite
13\Draw\GMS\"
copy /y aCalendar.gms "C:\Program Files\Corel\Corel Graphics 12\Draw\GMS\"
toolbar.vbs


-output:
C:\aCalendar>install.cmd

C:\aCalendar>runas /user:administrator 1.cmd
Enter the password for administrator:
Attempting to start 1.cmd as user "NONAME-PC\administrator" ...


...and that's it, nothing really happens.
I should mention that this all happens on limited user's account.
 
It is not quite true that "nothing" happens - your screen flashes briefly
after you have entered the administrator's password. The cause of the
problem is simple: install.bat is unable to locate 1.cmd, because you did
not fully qualify its location. If you want your batch files to be robust
then you MUST fully qualify all paths. This applies to your copy command
too: Instead of writing

copy /y aCalendar.gms "C:\Program Files\Corel\CorelDRAW Graphics Suite
X4\Draw\GMS\"
you should write
copy /y aCalendar.gms "C:\Program Files\Corel\CorelDRAW Graphics Suite
X4\Draw\GMS\" "c:\MyDrawings"
so that the destination is properly specified.

Now try this version of install.cmd:

runas /user:administrator c:\MyTools\1.cmd
 
Pegasus said:
It is not quite true that "nothing" happens - your screen flashes briefly
after you have entered the administrator's password. The cause of the
problem is simple: install.bat is unable to locate 1.cmd, because you did
not fully qualify its location. If you want your batch files to be robust
then you MUST fully qualify all paths. This applies to your copy command
too: Instead of writing

copy /y aCalendar.gms "C:\Program Files\Corel\CorelDRAW Graphics Suite
X4\Draw\GMS\"
you should write
copy /y aCalendar.gms "C:\Program Files\Corel\CorelDRAW Graphics Suite
X4\Draw\GMS\" "c:\MyDrawings"
so that the destination is properly specified.

Now try this version of install.cmd:

runas /user:administrator c:\MyTools\1.cmd

Yup that was it. Now if only i could make the batch files both execute in
the context of current directory of install.cmd.
 
vani said:
Yup that was it. Now if only i could make the batch files both execute in
the context of current directory of install.cmd.

Finally got it, with the help of %cd% and %1

Thanks.
 
Back
Top