Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get My Documents Path Name and Return the path

Status
Not open for further replies.

ezy123

Programmer
May 29, 2012
2
US
I am trying to run a script from an external program that will return the path to the "My Documents" folder:

Set wshshell = CreateObject("WScript.Shell")
Documents = wshShell.SpecialFolders("MyDocuments")
wshshell.SetText "tMyDocsPath", Documents

But it does not work. Can you tell me what is wrong I am a newb to VB Script
 
what is wscript.setText?

Code:
Set wshshell = CreateObject("WScript.Shell")
Documents = wshShell.SpecialFolders("MyDocuments")
[red]msgbox Documents[/red]
[s]wshshell.SetText "tMyDocsPath", Documents[/s]

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
When I need the "My Documents" folder, I use code similar to the following:
Code:
Const MY_DOCUMENTS = &H5&

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_DOCUMENTS)
Set objFolderItem = objFolder.Self
Wscript.Echo objFolderItem.Path

I'm unfamiliar with the shell object's .SetText method. What does it do? Do you have a link to more information? I looked on MSDN but didn't find a reference to it.
 
Well I am trying to return the path to the calling method from another language. SetText is "supposed" to set the value of the external variable "tMyDocsPath".

Here is an example of the code of the other language: LAUNCH EXTERNAL PROCESS("c:\folder\getMyDocsPath.vbs";$input;$output)
So in jges code will I be able to read the value of $output?

Thanks

 
What is the "other language"? Seems like you may be outside the scope of vbscript, and need assistance with this other language's parameters??
 
I assume the other language can work with StdIn, StdOut, and StdErr. If so, have your VBScript output the string to StdOut. See this technet page for some examples of VBScript input/output.

If not, I'd try having the VBScript create and write the output to a temporary text file that the other language can read from then delete.
 
Correct me, jges, if I'am wrong but can't the StdOut object only interact with the process in which it was invoked? If so, the script would need to be invoked by cscript.

ezy123, assuming a) the escape char in the "other" language is '\'. b) the first argument of the function accepts a command line command. c) the function is aware of environmental variables, the line above would probably look like this:
Code:
LAUNCH EXTERNAL PROCESS("%compsec% /c \"c:\folder\getMyDocsPath.vbs\"";$input;$output)
and getMyDocsPath.vbs would look something like
Code:
set objSshell = CreateObject("WScript.Shell")
strPath = objShell.SpecialFolders("MyDocuments")
wscript.stdout.write strPath
Although, I wasn't able to get this to work :) Therefore, your best bet may be to write the path to a temp file that the other language can open and read
getMyDocPath.vbs
Code:
set objShell = CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
set objStream = objFSO.OpenTextFile("c:\path.tmp", 2, true, 0)
strPath = objShell.SpecialFolders("MyDocuments")
objStream.Write strPath
objStream.close

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top