paydfody
asked on
Modify VBS Script to Write CVS file to a Share
Attention Experts,
I have a .vbs file that, when executed, generates a .csv file on the same drive/folder from which the the .vbs file was ran.
Example: The .vbs file is on the desktop. I execute the .vbs file, and a .csv file appears on the desktop.
Now, I need the outputted .csv file to be written to a network share, when the .vbs file is executed.
Example: The .vbs file is on the desktop. I execute the .vbs file, and a .csv file appears on a specified shared folder <that the user has 'write' access to, of course>.
Thanks in advance!
I have a .vbs file that, when executed, generates a .csv file on the same drive/folder from which the the .vbs file was ran.
Example: The .vbs file is on the desktop. I execute the .vbs file, and a .csv file appears on the desktop.
Now, I need the outputted .csv file to be written to a network share, when the .vbs file is executed.
Example: The .vbs file is on the desktop. I execute the .vbs file, and a .csv file appears on a specified shared folder <that the user has 'write' access to, of course>.
Thanks in advance!
Set oNet = CreateObject("Wscript.Network")
set oFSO = CreateObject("Scripting.FileSystemObject")
strComputer = "."
UserName = oNet.UserName
Set objOutputFile = oFSO.CreateTextFile(Username+".csv",True)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDrives = objWMIService.ExecQuery _
("Select * From Win32_LogicalDisk Where DriveType = 4")
'************
'get username and create row 1 with username
'************
objOutputFile.WriteLine(Username & ",")
'wscript.echo(UserName)
'************
'get drive letter and create row 2 with Drive letters
'************
For Each objDrive in colDrives
'Wscript.Echo "Drive letter: " & objDrive.DeviceID
objOutputFile.Write(objDrive.DeviceID & ",")
Next
'***********
'End Row 2
'***********
objOutputFile.WriteLine(" ")
'***********
'Get UNC and create column 3 under the corresponding drive letter
'***********
For Each objDrive in colDrives
'Wscript.Echo "Network path: " & objDrive.ProviderName
objOutputFile.Write(objDrive.ProviderName & ",")
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well, what does your code look like. It has to have somewhere the name of the file that is created. The fact that the file is created on the Desktop when you execute the script on the Desktop implies that the file name the csv file is given something like "data.csv", all you should have to do is change it an absolute path, ie: "\\remote_computer_name\sh ared_folde r\data.csv "
ASKER
My original code is posted, in the 'code snippet' section, directly under the question. I have been tweaking around with it, but I still haven't gotten it to write exactly where I want it. Anyways, the code is below (thanks):
Set oNet = CreateObject("Wscript.Netw ork")
set oFSO = CreateObject("Scripting.Fi leSystemOb ject")
strComputer = "."
UserName = oNet.UserName
Set objOutputFile = oFSO.CreateTextFile(Userna me+".csv", True)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDrives = objWMIService.ExecQuery _
("Select * From Win32_LogicalDisk Where DriveType = 4")
'************
'get username and create row 1 with username
'************
objOutputFile.WriteLine(Us ername & ",")
'wscript.echo(UserName)
'************
'get drive letter and create row 2 with Drive letters
'************
For Each objDrive in colDrives
'Wscript.Echo "Drive letter: " & objDrive.DeviceID
objOutputFile.Write(objDri ve.DeviceI D & ",")
Next
'***********
'End Row 2
'***********
objOutputFile.WriteLine(" ")
'***********
'Get UNC and create column 3 under the corresponding drive letter
'***********
For Each objDrive in colDrives
'Wscript.Echo "Network path: " & objDrive.ProviderName
objOutputFile.Write(objDri ve.Provide rName & ",")
Next
Set oNet = CreateObject("Wscript.Netw
set oFSO = CreateObject("Scripting.Fi
strComputer = "."
UserName = oNet.UserName
Set objOutputFile = oFSO.CreateTextFile(Userna
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDrives = objWMIService.ExecQuery _
("Select * From Win32_LogicalDisk Where DriveType = 4")
'************
'get username and create row 1 with username
'************
objOutputFile.WriteLine(Us
'wscript.echo(UserName)
'************
'get drive letter and create row 2 with Drive letters
'************
For Each objDrive in colDrives
'Wscript.Echo "Drive letter: " & objDrive.DeviceID
objOutputFile.Write(objDri
Next
'***********
'End Row 2
'***********
objOutputFile.WriteLine(" ")
'***********
'Get UNC and create column 3 under the corresponding drive letter
'***********
For Each objDrive in colDrives
'Wscript.Echo "Network path: " & objDrive.ProviderName
objOutputFile.Write(objDri
Next
ASKER
oobayly,
Good news. I've finally tweaked this thing like i need it. I appreciate the your thought-provoking ideas. Therefore, I am awarding you the 250 points.
Thanks again.
Good news. I've finally tweaked this thing like i need it. I appreciate the your thought-provoking ideas. Therefore, I am awarding you the 250 points.
Thanks again.
ASKER
That did not work. I'm not even sure how to add your mod to my code. Thanks, anyway.