My-script.vbs "c: \ scripts"
Must double quotation marks be added at both ends of the folder path? This example is not required. However, if the path contains spaces, double quotation marks must be added. The following command line does not work:
My-script.vbs c: \ documents ents and settings \ kmyer
As long as a parameter containing spaces is passed to the script, the entire parameter must be enclosed in double quotation marks (otherwise, this is not required ). In other words:
My-script.vbs "c: \ documents ents and settings \ kmyer"
This is how the command explains how the program works.
So what script will we run here? Good question. The final script is as follows:
Copy codeThe Code is as follows: Set objShell = CreateObject ("Wscript. Shell ")
StrPath = Wscript. Arguments (0)
StrPath = "assumer.exe/e," & strPath
ObjShell. Run strPath
As usual, this script does not have much content. We first create an instance of the Wscript. Shell object, which is a Windows Script Host object. We use it to run scripts or executable files in another Script. Then we get the first parameter (c: \ scripts) provided to the script and store it in the variable named strPath:
StrPath = Wscript. Arguments (0)
Should there be no doubt about this? Later, we will use the Run method to start Windows Resource Manager. However, before that, we should note that the Run method in WSH is basically the same as the Run dialog box. To use the Run dialog box to start Windows Resource Manager (focus on the C: \ Scripts folder), type the following code:
Assumer.exe/e, c: \ scripts
We found that the above syntax is the same as the syntax used to start Windows Resource Manager using the Run method: we only need to build the command and then execute:
StrPath = "assumer.exe/e," & strPath
ObjShell. Run strPath
In line 3, we run the cmder.exe/e command and append the folder path (the path is stored in the variable strPath). Then, the value of strPath is assumer.exe/e, c: \ scripts. In line 2, we call the Run method and pass the variable strPath as the command to be Run. If everything goes well (in terms of script writing, things always go well, right ?), Windows resource manager will open and focus on C: \ Scripts:
Cool.
So, what's wrong with this? Nothing. Everything works. The only drawback of this script is that you need to enter the complete path of the folder; when you try to open the folder C: \ Documents and Settings \ Default User \ Application Data \ Microsoft \ SystemCertificates \ My \ Certificates, this will become a problem. But since the system administrator always insists on using the command line, what options do we have to make?
Well, you can always try the GUI method (don't worry, we won't tell anyone ):Copy codeThe Code is as follows: Const WINDOW_HANDLE = 0
Const NO_OPTIONS = 0
Set objShell = CreateObject ("Shell. Application ")
Set objFolder = objShell. BrowseForFolder _
(WINDOW_HANDLE, "Select a folder:", NO_OPTIONS)
Set objFolderItem = objFolder. Self
StrPath = objFolderItem. Path
ObjShell. javase strPath
This script does not require any input. You only need to start the script, and then it will display the Browse folder dialog box:
Select a folder and click OK.
How does this script work? Well, let's first define a pair of constants: WINDOW_HANDLE and NO_OPTIONS. WINDOW_HANDLE is the constant required by the BrowseForFolder method. NO_OPTIONS only notifies the script that we want to display the standard "Browse folder" dialog box. Then, create an instance of the Shell. Application Object and use the following line of code to display the dialog box:
Set objFolder = objShell. BrowseForFolder _
(WINDOW_HANDLE, "Select a folder:", NO_OPTIONS)
After the dialog box is displayed, it will wait until we select a folder and click OK. Then we use the following two lines of code: 1) create an object reference to the selected folder; and 2) store the folder path to the variable strPath:
Set objFolderItem = objFolder. Self
StrPath = objFolderItem. Path
Now we only need to call the volume e method dedicated to opening Windows Resource Manager. By passing the variable strPath as a separate parameter, the Windows resource browser will focus on C: \ Scripts when it is opened:
ObjShell. javase strPath
What does this mean? This means that you can use a command prompt to open Windows resource manager or GUI to open Windows Resource Manager.