runas batch file

V

vanessa

Add pause right to the end of your install.cmd
e.g :

@echo off
echo Hello World...
pause
 
V

vani

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.
 
P

Pegasus [MVP]

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
 
V

vani

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.
 
V

vani

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top