![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Find my current drive letter and execute a program from it while i HI! The problem is that when i change the directory to usbletter:\SYSTEM i can't find a way to execute a program from the source directory where this script is located. Thank you in advance. If this helps, this script was meant to be ran from a CD. Then it would find the USB and so on. Sorry for my bad writing, im only 15 and im not a programmer i just want to edit this script and learn. Luka Here is the code: Look at the comments marked with ' Set objFSO = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("Wscript.Shell") Set colDrives = objFSO.Drives Set objEnv = objShell.Environment("PROCESS") objEnv("Year") = Year(now()) objEnv("Month") = Right("0" & Month(now()), 2) objEnv("Day") = Right("0" & Day(now()), 2) objEnv("Hour") = Right("0" & Hour(now()), 2) objEnv("Minute") = Right("0" & Minute(now()), 2) objEnv("Second") = Right("0" & Second(now()), 2) For Each objDrive in colDrives If objFSO.FileExists(objDrive.DriveLetter & ":\usbishere.txt") Then 'find my USB strPath = objDrive.Driveletter & ":" 'sets the USB letter sPathSpec = strPath & "\SYSTEM" 'change the path into a path on the USB CreateObject("Wscript.Shell").CurrentDirectory = sPathSpec 'now this is where i want to execute a program from the folder this script is located WHILE in the \SYSTEM folder on the usb. End If Next |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Find my current drive letter and execute a program from it while i Just to make sure I understand: you want to run a file at the location where the VBScript is running from - not necessarily on the USBdrive? If that's the case - the path of the running vbscript can be obtained with the following script: lenScriptFullName= len(wscript.scriptfullname) b = 0 for l = lenScriptFullName to 1 step -1 if b <> 1 then if mid(Wscript.scriptfullname, l, 1) <> "\" then a=a+1 else b=1 end if end if next totrim = len(wscript.scriptfullname) - a wscript.echo mid(wscript.scriptfullname, 1, totrim) Good luck sir Sam "Luka1993" <Luka1993@xxxxxx> wrote in message news:0CB252CE-0A69-4C3B-8811-51383D17767F@xxxxxx Quote: > HI! > > The problem is that when i change the directory to usbletter:\SYSTEM i > can't > find a way to execute a program from the source directory where this > script > is located. > > Thank you in advance. > > If this helps, this script was meant to be ran from a CD. Then it would > find > the USB and so on. > > Sorry for my bad writing, im only 15 and im not a programmer i just want > to > edit this script and learn. > > Luka > > Here is the code: Look at the comments marked with ' > > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objShell = CreateObject("Wscript.Shell") > Set colDrives = objFSO.Drives > Set objEnv = objShell.Environment("PROCESS") > > > objEnv("Year") = Year(now()) > objEnv("Month") = Right("0" & Month(now()), 2) > objEnv("Day") = Right("0" & Day(now()), 2) > objEnv("Hour") = Right("0" & Hour(now()), 2) > objEnv("Minute") = Right("0" & Minute(now()), 2) > objEnv("Second") = Right("0" & Second(now()), 2) > > For Each objDrive in colDrives > If objFSO.FileExists(objDrive.DriveLetter & ":\usbishere.txt") Then > 'find my USB > strPath = objDrive.Driveletter & ":" 'sets the USB letter > sPathSpec = strPath & "\SYSTEM" 'change the path into a path > on > the USB > CreateObject("Wscript.Shell").CurrentDirectory = sPathSpec > > 'now this is where i want to execute a program from the folder this script > is located WHILE in the \SYSTEM folder on the usb. > > End If > Next > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Find my current drive letter and execute a program from it while i "Luka1993" <Luka1993@xxxxxx> wrote in message news:0CB252CE-0A69-4C3B-8811-51383D17767F@xxxxxx Quote: > HI! > > The problem is that when i change the directory to usbletter:\SYSTEM i > can't > find a way to execute a program from the source directory where this > script > is located. 'GetParentFolderName' method: sScriptPath = objFSO.GetParentFolderName(WScript.ScriptFullName) |
My System Specs![]() |
| | #4 (permalink) |
| | Thank you Thanks to both of you. Yes, you both understood what i was trying to say but can you tell me where to put this code and how to use it because im 15 and a beginner :P. You alredy helped me alot ![]() Thank you! |
My System Specs![]() |
| | #5 (permalink) |
| | Thank you Thanks! You both understood me. I tried to put this in the code but i got and error. I am a beginner, so, what am i doing wrong? Set objFSO = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("Wscript.Shell") Set colDrives = objFSO.Drives Set objEnv = objShell.Environment("PROCESS") objEnv("Year") = Year(now()) objEnv("Month") = Right("0" & Month(now()), 2) objEnv("Day") = Right("0" & Day(now()), 2) objEnv("Hour") = Right("0" & Hour(now()), 2) objEnv("Minute") = Right("0" & Minute(now()), 2) objEnv("Second") = Right("0" & Second(now()), 2) For Each objDrive in objFSO.Drives If objDrive.IsReady Then If objFSO.FileExists(objDrive.DriveLetter & ":\flashdrive.txt") Then strPath = objDrive.Driveletter & ":" sPathSpec = strPath & "\SYSTEM\LOGS" CreateObject("Wscript.Shell").CurrentDirectory = sPathSpec sScriptPath = objFSO.GetParentFolderName(WScript.ScriptFullName) objShell.Run sScriptPath & "\example.exe" End If End If Next |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Thank you "Luka1993" <Luka1993@xxxxxx> wrote in message news:F67378F9-8DDE-4176-9F3C-5D4F062B30BD@xxxxxx Quote: > Thanks! You both understood me. > > I tried to put this in the code but i got and error. I am a beginner, so, > what am i doing wrong? > > Set objFSO = CreateObject("Scripting.FileSystemObject") > Set objShell = CreateObject("Wscript.Shell") > Set colDrives = objFSO.Drives > Set objEnv = objShell.Environment("PROCESS") > > objEnv("Year") = Year(now()) > objEnv("Month") = Right("0" & Month(now()), 2) > objEnv("Day") = Right("0" & Day(now()), 2) > objEnv("Hour") = Right("0" & Hour(now()), 2) > objEnv("Minute") = Right("0" & Minute(now()), 2) > objEnv("Second") = Right("0" & Second(now()), 2) > > For Each objDrive in objFSO.Drives > If objDrive.IsReady Then > If objFSO.FileExists(objDrive.DriveLetter & ":\flashdrive.txt") Then > strPath = objDrive.Driveletter & ":" > sPathSpec = strPath & "\SYSTEM\LOGS" > CreateObject("Wscript.Shell").CurrentDirectory = sPathSpec > sScriptPath = objFSO.GetParentFolderName(WScript.ScriptFullName) > objShell.Run sScriptPath & "\example.exe" > End If > End If > Next I have a question. Why are you changing the current directory of the script? Also, are you planning on running this script from a single flash drive or from many flash drives? If you are using a single flash drive, you could check for the 'VolumeName' or 'SerialNumber' properties and avoid creating and then testing for a trigger file. |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Thank you Hi! Thank you again. I am running this script from a CD wich will find a USB that me only will use. I could use the label to recognise it too but i didnt know how. The CD finds my USB and goes to USB:\SYSTEM folder and executes CD:\something.exe. If you have a better idea for making this file then suggest please ![]() The perfect idea would be: -get the USB letter from label -get the CD letter (where my script is) -go to USB:\SYSTEM -execute CD:\something.exe that is what i want actually :S |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Find my current drive letter and execute a program from it whilei Sam Hays wrote: Quote: > Just to make sure I understand: you want to run a file at the location > where the VBScript is running from - not necessarily on the USBdrive? > > If that's the case - the path of the running vbscript can be obtained > with the following script: > > lenScriptFullName= len(wscript.scriptfullname) > b = 0 > > for l = lenScriptFullName to 1 step -1 > if b <> 1 then > if mid(Wscript.scriptfullname, l, 1) <> "\" then > a=a+1 > else > b=1 > end if > end if > next > > totrim = len(wscript.scriptfullname) - a > wscript.echo mid(wscript.scriptfullname, 1, totrim) b = WScript.ScriptName c = Len(a) - Len(b) WScript.Echo Left(a, c) -- ..::[ Hz ]::. |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Thank you "Luka1993" <Luka1993@xxxxxx> wrote in message news:66EACF41-F7F3-4394-903F-E12F1A3EE60A@xxxxxx Quote: > Hi! > > Thank you again. > > I am running this script from a CD wich will find a USB that me only will > use. I could use the label to recognise it too but i didnt know how. You would replace: OLD: If objFSO.FileExists(objDrive.DriveLetter & ":\flashdrive.txt") Then NEW: If objDrive.VolumeName = "SCRIPTFLASH" Then You could also use the serial number: If objDrive.SerialNumber = &H50187D93 Then You can find it from the command line by typing 'vol {drive letter}' from a command prompt (ex: vol c . You will see output like:Volume in drive C has no label. Volume Serial Number is 5018-7D93 To use it in your script, just remove the dash from the center and prefix (&H) before it to tell VBScript it is a hexadecimal number. Quote: > The perfect idea would be: > > -get the USB letter from label use a trigger file. Quote: > -get the CD letter (where my script is) 'Scripting.FileSystemObject'. To get the drive letter of the drive where the script was launched from: sScriptDrive = objFSO.GetDriveName(WScript.ScriptFullName) To get the full path to the script: sScriptPath = objFSO.GetParentFolderName(WScript.ScriptFullName) Quote: > -go to USB:\SYSTEM objShell.CurrentDirectory = sPathSpec Quote: > -execute CD:\something.exe in quotes, though: objShell.Run """" & sScriptPath & "\example.exe" & """" Without the quote wrapping, your script would fail if there is a space in any of the folders in the path to the script itself. So, assuming that the serial number of your flash drive is '5018-7D93', your script could look like this: Set objFSO = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("Wscript.Shell") Set objEnv = objShell.Environment("PROCESS") objEnv("Year") = Year(now()) objEnv("Month") = Right("0" & Month(now()), 2) objEnv("Day") = Right("0" & Day(now()), 2) objEnv("Hour") = Right("0" & Hour(now()), 2) objEnv("Minute") = Right("0" & Minute(now()), 2) objEnv("Second") = Right("0" & Second(now()), 2) For Each objDrive in objFSO.Drives If objDrive.IsReady Then If objDrive.SerialNumber = &H50187D93 Then strPath = objDrive.Driveletter & ":" sPathSpec = strPath & "\SYSTEM\LOGS" objShell.CurrentDirectory = sPathSpec sScriptPath = objFSO.GetParentFolderName(WScript.ScriptFullName) objShell.Run """" & sScriptPath & "\example.exe" & """" End If End If Next |
My System Specs![]() |
| | #10 (permalink) |
| | Re: Thank you The script is working and i used the serial number, it really is a better idea ![]() This was exactly what i wanted ![]() Thank you soooo much!!! |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| How to execute external program from powershell | PowerShell | |||
| find the current stat and reboot | VB Script | |||
| find current boot configuration | Vista General | |||
| Re: cannot execute program in dir with space and argument | PowerShell | |||
| Execute scripts in current scope? | PowerShell | |||