Prev: How to pass argument to VBScript NOT via WScript
Next: VB Script - Check user for default password on remote workgroup machine
From: David C. Holley on 10 Dec 2009 17:50 I wrote the following script a couple of years back and just revisited it. While explorer opens, it fails to open to the designated folder. Exploer only opens to root C:\ sub openFolder (target) Set objShell = CreateObject("Wscript.Shell") objShell.Run "explorer.exe /e " & targetFolder Set objShell = Nothing end sub I've also tried explicity stating the path to no avail. sub openFolder (target) Set objShell = CreateObject("Wscript.Shell") objShell.Run "explorer.exe /e C:\Documents and Settings\dch3\My Documents\My Web Sites\MyOutlookToday\dch_091205-A_1" Set objShell = Nothing end sub
From: Todd Vargo on 10 Dec 2009 18:12 "David C. Holley" <David.C.Holley> wrote in message news:Or9qoseeKHA.2780(a)TK2MSFTNGP05.phx.gbl... > I wrote the following script a couple of years back and just revisited it. > While explorer opens, it fails to open to the designated folder. Exploer > only opens to root C:\ > > sub openFolder (target) > > > Set objShell = CreateObject("Wscript.Shell") > > objShell.Run "explorer.exe /e " & targetFolder > > Set objShell = Nothing > > end sub Your sub arg is named "target" but the .run command is using a name of "targetfolder". Note, if target contains spaces, then it must be quoted when passed to explorer. If it does not contain the quotes, then you need to add them. If Not Left(target,1) = Chr(34) Then target = Chr(34) & target If Not Right(target,1) = Chr(34) Then target = Chr(34) & target > > I've also tried explicity stating the path to no avail. > > sub openFolder (target) > > > Set objShell = CreateObject("Wscript.Shell") > > objShell.Run "explorer.exe /e C:\Documents and Settings\dch3\My > Documents\My Web Sites\MyOutlookToday\dch_091205-A_1" > > Set objShell = Nothing > > end sub Your path to the folder contains spaces but is not being passed to explorer as quoted. You need to provide quotes around the path. objShell.Run "explorer.exe /e " & """C:\Documents and Settings\ dch3\My Documents\My Web Sites\MyOutlookToday\dch_091205-A_1""" -- Todd Vargo (Post questions to group only. Remove "z" to email personal messages)
From: mayayana on 10 Dec 2009 18:40 In addition to Todd Vargo's points, you don't need to call Explorer at all. Just: objShell.Run "C:\whatever"
From: David C. Holley on 10 Dec 2009 19:04 What?! Somebody tampered with my post! "Todd Vargo" <tlvargo(a)sbcglobal.netz> wrote in message news:uyfMD5eeKHA.1824(a)TK2MSFTNGP04.phx.gbl... > > "David C. Holley" <David.C.Holley> wrote in message > news:Or9qoseeKHA.2780(a)TK2MSFTNGP05.phx.gbl... >> I wrote the following script a couple of years back and just revisited >> it. >> While explorer opens, it fails to open to the designated folder. Exploer >> only opens to root C:\ >> >> sub openFolder (target) >> >> >> Set objShell = CreateObject("Wscript.Shell") >> >> objShell.Run "explorer.exe /e " & targetFolder >> >> Set objShell = Nothing >> >> end sub > > Your sub arg is named "target" but the .run command is using a name of > "targetfolder". Note, if target contains spaces, then it must be quoted > when > passed to explorer. If it does not contain the quotes, then you need to > add > them. > > If Not Left(target,1) = Chr(34) Then target = Chr(34) & target > If Not Right(target,1) = Chr(34) Then target = Chr(34) & target > > >> >> I've also tried explicity stating the path to no avail. >> >> sub openFolder (target) >> >> >> Set objShell = CreateObject("Wscript.Shell") >> >> objShell.Run "explorer.exe /e C:\Documents and >> Settings\dch3\My >> Documents\My Web Sites\MyOutlookToday\dch_091205-A_1" >> >> Set objShell = Nothing >> >> end sub > > Your path to the folder contains spaces but is not being passed to > explorer > as quoted. You need to provide quotes around the path. > > objShell.Run "explorer.exe /e " & """C:\Documents and Settings\ > dch3\My Documents\My Web Sites\MyOutlookToday\dch_091205-A_1""" > > -- > Todd Vargo > (Post questions to group only. Remove "z" to email personal messages) >
From: Todd Vargo on 10 Dec 2009 23:58
mayayana wrote: > In addition to Todd Vargo's points, you > don't need to call Explorer at all. Just: > > objShell.Run "C:\whatever" That depends on whether explorer view or folder view is desired. Note, I missed that OP did not include a comma after the /e. The comma is required to open the folder in explorer view. Without it, explorer just opens in the root of C: as was described. objShell.Run "explorer.exe /e, " & target -- Todd Vargo (Post questions to group only. Remove "z" to email personal messages) |