gunsmokingman Posted February 17, 2005 Share Posted February 17, 2005 This Code Work OK, Except For Two ProblemIt Will Not Do ThisSOME-HD:\SomeApp.exeBut It Will Do ThisSOME-HD:\SomeFolder\SomeApp.exeIt Will Not Do ThisSOME-HD:\Some Folder\Some App.exeBut It Will Do ThisSOME-HD:\Some Folder\SomeApp.exeI would like to be able to do the blue highlighted one.Dim sh, fol, fs, lngView, strPathSet Shell = WScript.CreateObject("WScript.Shell")Set sh = CreateObject("Shell.Application")Set fs = CreateObject("Scripting.FileSystemObject")V = VbcrlfFUNCTION RTstrPrompt="This Will Open Only Folder Listed In A Root Drive. It Will Not Open Just The Root Drive!" & space(2) &_"Root=Any HD Or Partition" & space(5) & "Eg> Root:\" & space(2) & "Wrong" & space(5) & "EG1>Root:\SomeFolder" & space(2) & "Right"strTitle ="Gsm Open A Folder"RT = BrowseForFile(strPrompt, strTitle )End FunctionFunction GsmGetApp02 Gsm02=RTMsgBox Gsm02'GsmGetApp02 = (CreateObject("Wscript.shell").run (Chr(34) & "" & Gsm02 & "\spybotsd13.exe /silent"& Chr(34)))GsmGetApp02 = (CreateObject("Wscript.shell").run (Chr(34) & "" & Gsm02 & "\"& Chr(34)))End Function Function BrowseForFile(strPrompt, strTitle )On Error Resume NextIf Instr(TypeName(CreateObject("Shell.Application")), "Shell") = FALSE ThenELSEBrowseForFile = BrowseForFile_Shell(strPrompt)End IfEnd FunctionFunction BrowseForFile_Shell(strPrompt)lngView = SFVVO_SHOWALLOBJECTS Or SFVVO_SHOWEXTENSIONS Or SFVVO_SHOWFILES Or SFVVO_SHOWDRIVEstrPath = ""Set fol = sh.BrowseForFolder(&0, strPrompt, lngView, ssfDRIVES)On Error Resume NextstrPath = fol.ParentFolder.ParseName(fol.Title).PathIf strPath = ("*\(*:)") Then strPath = fol.TitleSet fol = fol.ParentFolderstrPath = fs.BuildPath("", strPath)End IfBrowseForFile_Shell = strPathEnd FunctionGsmGetApp02I Have Tried A Couble Of Different Ways On Trying ToGet It Like The Blue highlighted Ones But No Luck.Thanks for any help Link to comment Share on other sites More sharing options...
dman Posted February 18, 2005 Share Posted February 18, 2005 It seems to work OK. I renamed "spybotsd.exe" to "spy botsd.exe" and it works. there is no spybotsd13.exe file in the folder. Is this code just a test, or is that file actually there on your computer? What is the "xxx yyy.exe" file you are trying to run?Dim sh, fol, fs, lngView, strPathSet Shell = WScript.CreateObject("WScript.Shell")Set sh = CreateObject("Shell.Application")Set fs = CreateObject("Scripting.FileSystemObject")V = VbcrlfFUNCTION RTstrPrompt="This Will Open Only Folder Listed In A Root Drive. It Will Not Open Just The Root Drive!" & space(2) &_"Root=Any HD Or Partition" & space(5) & "Eg> Root:\" & space(2) & "Wrong" & space(5) & "EG1>Root:\SomeFolder" & space(2) & "Right"strTitle ="Gsm Open A Folder"RT = BrowseForFile(strPrompt, strTitle )End FunctionFunction GsmGetApp02Gsm02=RTMsgBox Gsm02GsmGetApp02 = (CreateObject("Wscript.shell").run (Chr(34) & "" & Gsm02 & "\spy botsd.exe"& Chr(34)))'GsmGetApp02 = (CreateObject("Wscript.shell").run (Chr(34) & "" & Gsm02 & "\"& Chr(34)))End FunctionFunction BrowseForFile(strPrompt, strTitle )On Error Resume NextIf Instr(TypeName(CreateObject("Shell.Application")), "Shell") = FALSE ThenELSEBrowseForFile = BrowseForFile_Shell(strPrompt)End IfEnd FunctionFunction BrowseForFile_Shell(strPrompt)lngView = SFVVO_SHOWALLOBJECTS Or SFVVO_SHOWEXTENSIONS Or SFVVO_SHOWFILES Or SFVVO_SHOWDRIVEstrPath = ""Set fol = sh.BrowseForFolder(&0, strPrompt, lngView, ssfDRIVES)On Error Resume NextstrPath = fol.ParentFolder.ParseName(fol.Title).PathIf strPath = ("*\(*:)") ThenstrPath = fol.TitleSet fol = fol.ParentFolderstrPath = fs.BuildPath("", strPath)End IfBrowseForFile_Shell = strPathEnd FunctionGsmGetApp02 Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 18, 2005 Author Share Posted February 18, 2005 This Is The problem hope this explains it betterThanks For Your Reply This Is A Template Of A ScriptSo The Main Thing Is I want to be able to pass the variblefrom C:\ D:\ etc, and also to be able to handle double spaces Link to comment Share on other sites More sharing options...
dman Posted February 18, 2005 Share Posted February 18, 2005 I found some stuff about wscript and file names with spaces. The suggestion is to enclose the exe in brackets with qoutes Ex. ["some app.exe"]http://www.foxite.com/archives/0000023492.htmI'm still not sure exactly what you are trying to do. Do you really just want to return a folder name, or would it be better to return a file name and path?If so you might want to try commondialog instead of shell.browseforfolder.Dim shell, xSet Shell = WScript.CreateObject("WScript.Shell")Set ObjFSO = CreateObject("UserAccounts.CommonDialog") ObjFSO.Filter = "Programs|*.exe|Scripts|*.vbs" InitFSO = ObjFSO.ShowOpenIf InitFSO = False Then Wscript.Echo "You did not select a file!" Wscript.QuitElse Wscript.Echo "You selected the file: " & ObjFSO.FileName x = shell.run (Chr(34) & ObjFSO.FileName & Chr(34))End If Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 18, 2005 Author Share Posted February 18, 2005 (edited) What Happen Is That If I go To This Will Not Work C:\Some.exeC is only a ExampleC:\This Wont RunBOOT000-0-1(C:)This Is The varible If I Use My Script That get passed back To The scriptIf I Was To Go To C:\FolderI get the correct varible passed back to my script.Test Dir For Space Varible Pass To ScriptH:\Test FolderFunction GsmGetApp02 Gsm02=RTMsgBox Gsm02GsmGetApp02 = (CreateObject("Wscript.shell").run (Chr(34) & "" & Gsm02 & "\UaKill Time.HTA "& Chr(34)))End FunctionThe script works fine as it is I just want to take out those flaw with it.Got The Space Issue To Work Only Problem Is It Wont Open C:\ or D:\ Or E:\ etcThanks For Your Help Edited February 18, 2005 by gunsmokingman Link to comment Share on other sites More sharing options...
dman Posted February 18, 2005 Share Posted February 18, 2005 I'm not too up on vbscript, so I'm not sure if there is a way to return just the drive letter, but you can always brute-force parse it. If the return is a root drive folder name, the return will always include the drive letter and end with "". This combo would be invalid in this position if you were returning a subfolder name, so you can detect this and parse out all but the drive letter and colon and you should be good. Excerpt from BrowseForFile_Shell(strPrompt)If Right(fol.Title, 2) = ":)" Then 'must be a root drive strpath = Mid(fol.Title, len(fol.Title) - 2, 2) else 'is a subfolder strPath = fol.ParentFolder.ParseName(fol.Title).PathEnd If Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 19, 2005 Author Share Posted February 19, 2005 Thank you that was the perfect code.The script now passes the correct varible.Final CodeIt Will Open Any Folder Or Partition Now CorrectlySet Shell = WScript.CreateObject("WScript.Shell")AP = Shell.ExpandEnvironmentStrings("%AllUsersProfile%")UP = Shell.ExpandEnvironmentStrings("%UserProfile%")SD = Shell.ExpandEnvironmentStrings("%SystemDrive%")SP = Shell.ExpandEnvironmentStrings("%SystemDrive%\Program Files")WD= Shell.ExpandEnvironmentStrings("%Windir%\")FUNCTION RTRT = BrowseForFile("Open A Folder Than Use Right Click Functions:" & Vbcrlf &_"This Will Not Open Root Drives" & Vbcrlf & "Eg C:\ Will not Open EG1 C:\SomeFolder Will Open" & vbcrlf & "Test Line 1","Select File")End FunctionFunction GsmGetApp02 Gsm02=RTMsgBox Gsm02GsmGetApp02 = (CreateObject("Wscript.shell").run (Chr(34) & "" & Gsm02 & ""& Chr(34)))End Function Function BrowseForFile(strPrompt, strTitle )On Error Resume NextIf Instr(TypeName(CreateObject("Shell.Application")), "Shell") = 0 Thenmsgbox "Error Happen!"ELSEBrowseForFile = BrowseForFile_Shell(strPrompt)End IfEnd FunctionFunction BrowseForFile_Shell(strPrompt)Dim sh, fol, fs, lngView, strPathSet sh = CreateObject("Shell.Application")Set fs = CreateObject("Scripting.FileSystemObject")lngView = SFVVO_SHOWALLOBJECTS Or SFVVO_SHOWEXTENSIONS Or SFVVO_SHOWFILES Or SFVVO_SHOWDRIVEstrPath = ""'Set fol = sh.BrowseForFolder(&0, strPrompt, lngView, ssfDRIVES)Set fol = sh.BrowseForFolder(&0, strPrompt, lngView)'(["My App.exe"])On Error Resume NextstrPath = fol.ParentFolder.ParseName(fol.Title).PathIf Right(fol.Title, 2) = ":)" Then 'must be a root drive strpath = Mid(fol.Title, len(fol.Title) - 2, 2) else 'is a subfolder strPath = fol.ParentFolder.ParseName(fol.Title).PathEnd IfIf strPath = "" ThenstrPath = fol.TitleSet fol = fol.ParentFolderstrPath = fs.BuildPath("", strPath)End IfBrowseForFile_Shell = strPathEnd FunctionGsmGetApp02 Link to comment Share on other sites More sharing options...
dman Posted February 19, 2005 Share Posted February 19, 2005 Glad I could help Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 19, 2005 Author Share Posted February 19, 2005 (edited) This Is What Your Code Help , Me With It MakeCab.vbs It Will MakeCab And Than A Folder Than Delete The SourceAnd Leave A Expand.cmd For Later use.Thanks Again For Your Help on error resume next Dim Shell, SD, fso, sh, fs, objFSO, V ,WD, RT V = Vbcrlf Set Shell = WScript.CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") Set sh = CreateObject("WScript.Shell") Set fs = CreateObject("Scripting.FileSystemObject") Set objFSO = CreateObject("Scripting.FileSystemObject") SD = Shell.ExpandEnvironmentStrings("%SystemDrive%") RT = BrowseForFile("Open A Folder Than Use Right Click Functions:", "Select File") Function BrowseForFile(strPrompt, strTitle) On Error Resume Next If Instr(TypeName(CreateObject("Shell.Application")), "Shell") = 0 Then BrowseForFile = InputBox(strPrompt, strTitle, WScript.ScriptFullName,"HELLO") Else BrowseForFile = BrowseForFile_Shell(strPrompt) End If End Function Function BrowseForFile_Shell(strPrompt) Dim sh, fol, fs, lngView, strPath Set sh = CreateObject("Shell.Application") Set fs = CreateObject("Scripting.FileSystemObject") lngView = SFVVO_SHOWALLOBJECTS Or SFVVO_SHOWEXTENSIONS Or SFVVO_SHOWFILES strPath = "" Set fol = sh.BrowseForFolder(&0, strPrompt, lngView, ssfDRIVES) On Error Resume Next strPath = fol.ParentFolder.ParseName(fol.Title).Path If Right(fol.Title, 2) = ":)" Then 'must be a root drive strpath = Mid(fol.Title, len(fol.Title) - 2, 2) else 'is a subfolder strPath = fol.ParentFolder.ParseName(fol.Title).Path End If If strPath = "" Then strPath = fol.Title Set fol = fol.ParentFolder strPath = fs.BuildPath(fol.ParentFolder.ParseName(fol.Title).Path, strPath) End If BrowseForFile_Shell = strPath End Function '''''''FUNCTION THIS OPEN THE BROWS FOR DIALOG Gsm02=Rt MsgBox Gsm02 '''''''FUNCTION THIS OPEN THE BROWS FOR DIALOG Set f = fso.CreateFolder(SD & "\TEMP") Gsm = Msgbox (space(7) & "Preparing MakecaB Process" & V & "This Will MakecaB The Directory" & V & Gsm02 & V &_ "Yes Will Begin The Process" & V & "No Will Quit And Do Nothing", 4 + 48, "Please Read This") if Gsm = vbyes Then On Error Goto 0 Ed = msgbox ("Here The Location:" & V & Gsm02 , 0 +64,"Here What You Choosed") wscript.sleep 1200 Set ts = fs.OpenTextFile(Rt & "\MKdel.cmd", 2, True) ts.WriteLine "echo off && Cls && Color 9f && Mode Con: Cols=70 Lines=9" ts.WriteLine "set RT=" & Gsm02 ts.WriteLine "ping -n 1 127.0.0.1>nul" ts.WriteLine "Title MakecaB IN :-^>" & Gsm02 'ts.WriteLine "for %%i in (%RT%\*.*) do makecab /D CompressionType=LZX /D CompressionMemory=21 %1 %2 %%i && move %RT%\*.*_ %systemdrive%\Temp\" ts.WriteLine "for %%i in (""%RT%\*.*"") do makecab /D CompressionType=LZX /D CompressionMemory=21 %1 %2 ""%%i"" && move *.*_ %systemdrive%\Temp\" ts.Close wscript.sleep 500 msgbox space(7) & "Preparing To Run The Cmd" & V & "In This Location: " & Gsm02 ,0+48,"Beginning MakeCaB" wscript.sleep 500 Set fso = CreateObject("Scripting.FileSystemObject") Set oWS = WScript.CreateObject("WScript.Shell") 'CreateObject("WScript.Shell").Run(Gsm02 & "\MKdel.cmd") CreateObject("WScript.Shell").Run( Chr(34) & Gsm02 & "\MKdel.cmd" & Chr(34)) wscript.sleep 3000 msgbox "When The Cmd Window Closes" & V & "Press Button To Continue", 0 + 64, "Waiting For MakacaB" On Error Resume Next Set objFSO = CreateObject("Scripting.FileSystemObject") Set fso = CreateObject("Scripting.FileSystemObject") set objShell = CreateObject("Shell.Application") set objFolder = objShell.NameSpace(SD & "\TEMP") Wscript.sleep 2000 if not objFolder is nothing then objFolder.MoveHere(SD & "\*.*_") 'Set f = fso.CreateFolder(RT & "\Archive\") fso.Deletefile( SD & "\*.*_") ON ERROR RESUME NEXT Set fso = CreateObject("Scripting.FileSystemObject") fso.DeleteFile( RT & "\*.*") wscript.sleep 3000 MSGBOX space(7) & "Phase One Completed" & V & "Preparing For Phase Two", 0 + 64, "Preparing Phase Two" set objFolder = objShell.NameSpace(Gsm02 & "\") objFolder.MoveHere(SD & "\TEMP\*.*_") wscript.sleep 3000 MSGBOX space(7) & "Preparing Final Phase" & space(7) & V & "This Will Leave A Expand Cmd" & V &_ "In : " & RT & V & " Name Of The Cmd Is : ExpandArch.cmd", 0 + 64, "Phase Two" Set fs = CreateObject("Scripting.FileSystemObject") Set ED = fs.OpenTextFile(RT & "\ExpandArch.cmd", 2, True) ED.WriteLine "ECHO OFF && cls && color f2 && mode 69,9" ED.WriteLine "Title EXPAND Archive " ED.WriteLine "set RT=%CD%" ED.WriteLine "mkdir ""%RT%\Archive""" ED.WriteLine "for %%i in (""%RT%\*.*"") do EXPAND *.*_ /R && Move *.*_ ""%RT%\Archive"" && ping -n 1 127.0.0.1>nul" ED.WriteLine "ping -n 1 127.0.0.1>nul" ED.WriteLine "Cls && mode 55,5 && Color 9f && Echo. && Echo Would You Like To Keep The Archive?" ED.WriteLine "Echo Yes To Keep Archive No To Delete Archive" ED.WriteLine "Set /P Choice=Yes To Keep No To Delete :-^> " ED.WriteLine "Goto %Choice%" ED.WriteLine ":NO && Cls && Title Remove %RT%\Archive" ED.WriteLine "del /s /q ""%RT%\Archive\*.*_""" ED.WriteLine "ping -n 1 127.0.0.1>nul" ED.WriteLine "Rmdir /s /q " & Chr(34) & "%RT%\Archive" & chr(34) ED.WriteLine "ping -n 1 127.0.0.1>nul" ED.WriteLine "Echo. && Echo %RT%\Archive && Echo Removed && Ping -3 127.0.0.0.1>nul && Goto Quit" ED.WriteLine ":Yes && Cls && Title Keeping %RT%\Archive" ED.WriteLine "Echo. && Echo keeping && Echo %RT%\Archive && Ping -3 127.0.0.0.1>nul && Goto Quit" ED.WriteLine ":Quit && Echo Goodbye && ping -n 3 127.0.0.1>nul && exit" ED.Close wscript.sleep 500 ON ERROR RESUME NEXT Set fso = CreateObject("Scripting.FileSystemObject") fso.Deletefolder( SD & "\TEMP") Wscript.sleep 1000 end if set objShell = nothing set objFolder = nothing MsgBox "Completed Archive Process" & V & " Thank-You For Trying This" & V & "Gunsmokingman", 0 + 64 ,"Gsm Says Good Bye" Set fso = CreateObject("Scripting.FileSystemObject") on Error Resume Next fso.DeleteFile( Chr(34) & Gsm02 & "\MKdel.cmd" & chr(34)) fso.DeleteFile( SD & "\GmanMkcaB.vbs") set fso = nothing else end if if Gsm = vbno Then On Error Resume Next msgbox "Preparing To Quit" & V & "Cleaning Up Files Made", 0 + 64, "Gsm Says Good-Bye" Set fso = CreateObject("Scripting.FileSystemObject") fso.Deletefolder( SD & "\TEMP") fso.DeleteFile( Gsm02 & "\MKdel.cmd") fso.DeleteFile( SD & "\GmanMkcaB.vbs")elseend if Edited January 5, 2006 by gunsmokingman Link to comment Share on other sites More sharing options...
dman Posted February 19, 2005 Share Posted February 19, 2005 Nice work, Gman!Your code runs great. I learn a few things from you, too. Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 19, 2005 Author Share Posted February 19, 2005 (edited) I Just Ran This Code You Posted And I Am,Dim shell, xSet Shell = WScript.CreateObject("WScript.Shell")Set ObjFSO = CreateObject("UserAccounts.CommonDialog") ObjFSO.Filter = "Programs|*.exe|Scripts|*.vbs" InitFSO = ObjFSO.ShowOpenIf InitFSO = False Then Wscript.Echo "You did not select a file!" Wscript.QuitElse Wscript.Echo "You selected the file: " & ObjFSO.FileName x = shell.run (Chr(34) & ObjFSO.FileName & Chr(34))End IfGoing To Use It In My Next ScriptDim shell, X1, X2, X3Set Shell = WScript.CreateObject("WScript.Shell")Set ObjFSO = CreateObject("UserAccounts.CommonDialog") function recallX2=ObjFSO.FileNameMsgBox X2, 0 + 64,"Recall Varible"end functionfunction NotThereX3="No File Was Selected" & Vbcrlf & "Preparing To Quit" MsgBox X3, 0 + 64,"Exiting Script"end functionFunction GsmGetFileObjFSO.Filter = "All Files|*.*" InitFSO = ObjFSO.ShowOpenIf InitFSO = False Then NotThere Wscript.QuitElse X2=ObjFSO.FileName recall X1 = shell.run (Chr(34) & ObjFSO.FileName & Chr(34)) Set Shell = nothing Set ObjFSO = nothingEnd IfEnd FunctionGsmGetFileThanks Again Ill also use the above Code In some Other ScriptsThat A Nice Little Piece Of Code There. Edited February 19, 2005 by gunsmokingman Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now