Page 1 of 1

Help writing a .bat file to launch a windows script.

Posted: 26 Jul 2016 12:34
by md73code
I'm trying to create a simple .bat file to run GPUView with a click of a icon. I need to run "log.cmd" from the "C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\gpuview" directory in an Administrativs CMD Prompt. I dont have much experience with .bat files so any help would be appreciated.

This is my latest attempt:
START "runas /user:administrator" cmd /K "cd C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\gpuview\log.cmd"

But I get a "The directory name is invalid." message.

Re: Help writing a .bat file to launch a windows script.

Posted: 26 Jul 2016 13:24
by aGerman
Try that

Code: Select all

START "runas /user:administrator" cmd /c "cd "C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\gpuview" &call "log.cmd""

Regards
aGerman

Re: Help writing a .bat file to launch a windows script.

Posted: 26 Jul 2016 14:54
by md73code
Thanks that works! But is there a way to keep the CMD Prompt window open after the script has executed?

Re: Help writing a .bat file to launch a windows script.

Posted: 26 Jul 2016 15:55
by aGerman
My fault. I changed your cmd /k to cmd /c. You just have to change it back.

Regards
aGerman

Re: Help writing a .bat file to launch a windows script.

Posted: 26 Jul 2016 17:00
by foxidrive
The start command should begin like this to cater for the title field that had made people bald ever since it was added to Windows.

Code: Select all

start ""


People tear their hair out in frustration. ;)

Your runas command isn't being launched, in the way I understand it.

Re: Help writing a .bat file to launch a windows script.

Posted: 26 Jul 2016 17:11
by aGerman
A few minutes ago I explained it in a German forum but I didn't even notice it in this thread :roll:

Re: Help writing a .bat file to launch a windows script.

Posted: 26 Jul 2016 22:26
by foxidrive
aGerman wrote:A few minutes ago I explained it in a German forum but I didn't even notice it in this thread :roll:

I've been in that position so many times myself with different things.

Eyeballs MK 1 aren't all that reliable. :D

Re: Help writing a .bat file to launch a windows script.

Posted: 27 Jul 2016 10:05
by md73code
aGerman wrote:My fault. I changed your cmd /k to cmd /c. You just have to change it back.

Regards
aGerman


Thank you!

This takes me to my next problem. While the CMD window is open i need it to wait for 45 seconds and then i need it to send "log.cmd" again to stop the GPUView capture.

Heres my non working attempt:

Code: Select all

START "runas /user:administrator" cmd /k "cd "C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\gpuview" &call "log.cmd"

SLEEP 45

&call "log.cmd""

Re: Help writing a .bat file to launch a windows script.

Posted: 27 Jul 2016 10:18
by Squashman
SLEEP has been replaced with the TIMEOUT command.

Re: Help writing a .bat file to launch a windows script.

Posted: 27 Jul 2016 10:56
by md73code
TIMEOUT worked! But the Timeout countdown is happening in a new CMD window. I need the timeout to happen in the original window that we call "log.cmd" on. and then call "log.cmd" again after the timeout.

Re: Help writing a .bat file to launch a windows script.

Posted: 27 Jul 2016 12:12
by foxidrive
Manveer Dhillon wrote:Heres my non working attempt:

Code: Select all

START "runas /user:administrator" cmd /k "cd "C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\gpuview"

You didn't understand my post. And we don't know what you expect from the runas command.

Re: Help writing a .bat file to launch a windows script.

Posted: 27 Jul 2016 13:02
by md73code
Yes my runas command is not working. With that command I just want to run this .bat file as Administrator.

Re: Help writing a .bat file to launch a windows script.

Posted: 27 Jul 2016 14:49
by aGerman
Try

Code: Select all

START "" runas /user:administrator "cmd /k \"cd \"C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\gpuview\"^&call \"log.cmd\"\""


Manveer Dhillon wrote:Yes my runas command is not working. With that command I just want to run this .bat file as Administrator.

No idea what you are talking about. The RUNAS will be applied to the cmd /k and thus, it's also applied to the log.cmd. You will be asked to enter the password for the administrator account.

Regards
aGerman

Re: Help writing a .bat file to launch a windows script.

Posted: 30 Jul 2016 02:45
by foxidrive
Manveer Dhillon wrote:Yes my runas command is not working.


Did you sort that out?

Is it this script meant for your own machine, or for general use on other PCs?