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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
md73code
Posts: 16
Joined: 29 Jul 2015 15:29

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

#1 Post by md73code » 26 Jul 2016 12:34

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.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

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

#2 Post by aGerman » 26 Jul 2016 13:24

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

md73code
Posts: 16
Joined: 29 Jul 2015 15:29

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

#3 Post by md73code » 26 Jul 2016 14:54

Thanks that works! But is there a way to keep the CMD Prompt window open after the script has executed?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

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

#4 Post by aGerman » 26 Jul 2016 15:55

My fault. I changed your cmd /k to cmd /c. You just have to change it back.

Regards
aGerman

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#5 Post by foxidrive » 26 Jul 2016 17:00

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.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

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

#6 Post by aGerman » 26 Jul 2016 17:11

A few minutes ago I explained it in a German forum but I didn't even notice it in this thread :roll:

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#7 Post by foxidrive » 26 Jul 2016 22:26

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

md73code
Posts: 16
Joined: 29 Jul 2015 15:29

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

#8 Post by md73code » 27 Jul 2016 10:05

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""

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

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

#9 Post by Squashman » 27 Jul 2016 10:18

SLEEP has been replaced with the TIMEOUT command.

md73code
Posts: 16
Joined: 29 Jul 2015 15:29

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

#10 Post by md73code » 27 Jul 2016 10:56

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#11 Post by foxidrive » 27 Jul 2016 12:12

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.

md73code
Posts: 16
Joined: 29 Jul 2015 15:29

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

#12 Post by md73code » 27 Jul 2016 13:02

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

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

#13 Post by aGerman » 27 Jul 2016 14:49

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#14 Post by foxidrive » 30 Jul 2016 02:45

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?

Post Reply