Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Generic User Avatar

Batch file (basics!)


  • Please log in to reply
33 replies to this topic

#16 Romeo29

Romeo29

    Learning To Bleep


  •  Avatar image
  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:02:36 AM

Posted 05 November 2013 - 11:47 AM

 

 

Try wrapping the script path inside a pair of quotes " ", e.g.,

start "C:\Hello\This is my script\beep.bat"

Hi Romeo - Different error message! (Which may be a small step??)

 

So when I run the command in quotes I get the following message within the cmd prompt :

 

ReY0acF.png

 

 

"C:\Users\...\programs" appears to be a folder. Typing a folder name will do nothing. Windows is displaying an error message as expected because it does not know what you are trying to do.

 

Where is your script file (with extension) is stored? For example a file name hello.bat is stored inside c:\users\romeo\ so full path name is folder name + filename, in this case, c:\users\romeo\hello.bat

 

I think you are copying the location name from the Windows Explorer, but are not adding the filename after it.


Edited by Romeo29, 05 November 2013 - 11:48 AM.


BC AdBot (Login to Remove)

 


#17 teatrap

teatrap
  • Topic Starter

  •  Avatar image
  • Members
  • 121 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:36 AM

Posted 05 November 2013 - 11:53 AM

Hi Romeo - Well what I've been doing is putting the script into notepad, saving that as a Batch file then expecting to be able to open the batch file, that will run the script which will then open the folder / document. 

 

Whey I just got It to open a picture whilst going through this  :lol:

 

a7g0hBX.png

 

 

So - I can't open folders using a script is that correct? 


Operating system_Windows 8.1 Pro with Media Center (9600)
CPU_Intel® Core™ i7-4700MQ CPU @ 2.40GHz
Motherboard_Hewlett-Packard (1966)
RAM_12063mb
Hard Drive_931gb (HGST HTS541010A9E680)
Graphics card_Intel® HD Graphics 4600
Sound card_IDT High Definition Audio CODEC


#18 Romeo29

Romeo29

    Learning To Bleep


  •  Avatar image
  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:02:36 AM

Posted 05 November 2013 - 11:57 AM

You can open the folder with script, just prepend the folder name with Explorer.exe and space. For example, to open "C:\Program Files",

%WinDir%\Explorer.exe "C:\Program Files"

start uses default associated Windows program to process whatever you put after it. You can use it to open a website, e.g.,

start http://www.bleepingcomputer.com/

Edited by Romeo29, 05 November 2013 - 12:00 PM.


#19 teatrap

teatrap
  • Topic Starter

  •  Avatar image
  • Members
  • 121 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:36 AM

Posted 05 November 2013 - 11:58 AM

 

You can open the folder with script, just prepend the folder name with start and space. For exampe, to open "C:\Program Files",

start "C:\Program Files"

start uses default associated Windows program to process whatever you put after it. You can use it to open a website, e.g.,

start http://www.bleepingcomputer.com/

So it basically double clicks whatever comes after start... ? Ish...


Operating system_Windows 8.1 Pro with Media Center (9600)
CPU_Intel® Core™ i7-4700MQ CPU @ 2.40GHz
Motherboard_Hewlett-Packard (1966)
RAM_12063mb
Hard Drive_931gb (HGST HTS541010A9E680)
Graphics card_Intel® HD Graphics 4600
Sound card_IDT High Definition Audio CODEC


#20 teatrap

teatrap
  • Topic Starter

  •  Avatar image
  • Members
  • 121 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:36 AM

Posted 05 November 2013 - 12:00 PM

If i use the 

 

start "C:\Program Files"

 

that you mentioned I get another dos window come up like this

 

mnlfnDH.png

 

not an actual folder, is that what's meant to happen? 


Operating system_Windows 8.1 Pro with Media Center (9600)
CPU_Intel® Core™ i7-4700MQ CPU @ 2.40GHz
Motherboard_Hewlett-Packard (1966)
RAM_12063mb
Hard Drive_931gb (HGST HTS541010A9E680)
Graphics card_Intel® HD Graphics 4600
Sound card_IDT High Definition Audio CODEC


#21 Romeo29

Romeo29

    Learning To Bleep


  •  Avatar image
  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:02:36 AM

Posted 05 November 2013 - 12:03 PM

If i use the 

 

start "C:\Program Files"

 

that you mentioned I get another dos window come up like this

 

mnlfnDH.png

 

not an actual folder, is that what's meant to happen? 

 

I wrote in haste, edited the post, but you are fast :)

folder is opened with explorer.exe while files with start.


Edited by Romeo29, 05 November 2013 - 12:05 PM.


#22 teatrap

teatrap
  • Topic Starter

  •  Avatar image
  • Members
  • 121 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:36 AM

Posted 05 November 2013 - 12:16 PM

Ah crap sorry Romeo - feel free to delete those post's if you have rights. 

 

Right OK, so the "start" function is just for opening files, the "explroer.exe" is used for folders - which is accessed using %WinDir%

 

What is the command that is used for programs? Say I had the URL of a program on my computer and wanted to trigger it opening with a script? 

 

Thanks. 


Operating system_Windows 8.1 Pro with Media Center (9600)
CPU_Intel® Core™ i7-4700MQ CPU @ 2.40GHz
Motherboard_Hewlett-Packard (1966)
RAM_12063mb
Hard Drive_931gb (HGST HTS541010A9E680)
Graphics card_Intel® HD Graphics 4600
Sound card_IDT High Definition Audio CODEC


#23 Romeo29

Romeo29

    Learning To Bleep


  •  Avatar image
  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:02:36 AM

Posted 05 November 2013 - 12:28 PM

For programs, you do not need anything, just type the full path name (folder + filename with extension). Like C:\Windows\Notepad.exe

But you can also use start like, start c:\Windows\notepad.exe

 

The benefit of using start is that it can be used to control the program in many ways, open it minimized, maximized, control process priority etc.

 

e.g. to open Notepad minimized, start /min c:\windows\notepad.exe

 

type start /? to see more options.



#24 teatrap

teatrap
  • Topic Starter

  •  Avatar image
  • Members
  • 121 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:36 AM

Posted 05 November 2013 - 12:30 PM

Cheers Romeo - Lots of programs (all?) have their own function's that can be triggered using DOS commands, say Open Anti Malware Bytes - Perform Quick Scan - would the start command be used to execute something like this? 

 

thanks 


Operating system_Windows 8.1 Pro with Media Center (9600)
CPU_Intel® Core™ i7-4700MQ CPU @ 2.40GHz
Motherboard_Hewlett-Packard (1966)
RAM_12063mb
Hard Drive_931gb (HGST HTS541010A9E680)
Graphics card_Intel® HD Graphics 4600
Sound card_IDT High Definition Audio CODEC


#25 Romeo29

Romeo29

    Learning To Bleep


  •  Avatar image
  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:02:36 AM

Posted 05 November 2013 - 12:43 PM

Yes. some program has their command line parameters so they can be used in scripts.

 

For MBAM, to run quickscan : "%programfiles%\Malwarebytes' Anti-Malware\mbam.exe" /scan -quick

 

Obviously change the path to wherever your mbam.exe is located.

 

If you want to auto-terminate after scanning, then append -terminate too.

 

You can find full list of command line parameters in the MBAM help file.


Edited by Romeo29, 05 November 2013 - 12:44 PM.


#26 teatrap

teatrap
  • Topic Starter

  •  Avatar image
  • Members
  • 121 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:36 AM

Posted 05 November 2013 - 12:48 PM

Cheers Romeo - I don't understand why you've written "%programfiles%\Malwarebytes....." Rather than the script that you used in post #24  start /min c:\windows\

 

Is it because it's a third party product? 


Operating system_Windows 8.1 Pro with Media Center (9600)
CPU_Intel® Core™ i7-4700MQ CPU @ 2.40GHz
Motherboard_Hewlett-Packard (1966)
RAM_12063mb
Hard Drive_931gb (HGST HTS541010A9E680)
Graphics card_Intel® HD Graphics 4600
Sound card_IDT High Definition Audio CODEC


#27 Romeo29

Romeo29

    Learning To Bleep


  •  Avatar image
  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:02:36 AM

Posted 05 November 2013 - 01:09 PM

%programfiles% is a system variable which expands to your C:\Program Files\ automatically. So instead of writing C:\Program Files you can write %programfiles%.

 

 

"%programfiles%\Malwarebytes' Anti-Malware\mbam.exe" /scan -quick

 

becomes

 

"C:\Program Files\Malwarebytes' Anti-Malware\mbam.exe" /scan -quick

 

C:\Program Files\Malwarebytes' Anti-Malware\ is the folder where MBAM.exe is located, so we have to specify it :)

 

Why? Suppose some user has installed Windows in D: drive, his/her path would be D:\Program Files. But if we use %programfiles%, it automatically translates to ........

 

You can still use start but why use something if it is not really required?


Edited by Romeo29, 05 November 2013 - 01:10 PM.


#28 teatrap

teatrap
  • Topic Starter

  •  Avatar image
  • Members
  • 121 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:08:36 AM

Posted 05 November 2013 - 01:33 PM

Definitely! The less needed the better :) It's all new to me, thanks. 

 

I'm trying to open CamStudio Using this method though and it doesn't seem to be working out. 

 

%programfiles%\CamStudio Recorder.exe

 

ajnCRXh.png

 

:? 


Operating system_Windows 8.1 Pro with Media Center (9600)
CPU_Intel® Core™ i7-4700MQ CPU @ 2.40GHz
Motherboard_Hewlett-Packard (1966)
RAM_12063mb
Hard Drive_931gb (HGST HTS541010A9E680)
Graphics card_Intel® HD Graphics 4600
Sound card_IDT High Definition Audio CODEC


#29 Romeo29

Romeo29

    Learning To Bleep


  •  Avatar image
  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:02:36 AM

Posted 05 November 2013 - 02:08 PM

Perhaps because the program does not exist in that folder.



#30 ratbuddy

ratbuddy

  •  Avatar image
  • Members
  • 26 posts
  • OFFLINE
  •  
  • Local time:02:36 AM

Posted 06 November 2013 - 02:10 PM

teatrap buddy, I suggest you open a command prompt and play around. Use cd (folder) to change directory, and dir to see what's in there. Use dir /p if there is too much scrolling past. Try typing the names of some .exe files you find, although perhaps google what they do first - you don't want to format your hard drive or anything by accident.

 

Once you know your way around the command prompt and understand the difference between files and folders, you'll have a much better understand of how to work with batch files.


Edited by ratbuddy, 06 November 2013 - 02:44 PM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users