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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to Echo and Print results to txt

Status
Not open for further replies.

eGeeked

Programmer
Dec 29, 2011
4
US
I am new here and new to vbs any help to get this working as I see it working would be amazing. I work for a not for profit and we have thousands of PC's I have to support. Part of which is we are creating login scripts manually for each one and it is driving me insane. I found two bits of code I am trying to push together to work as one. Essentially the first section pulls the mapped drives from a remote device and the second section prints the results to a txt file. I have it working to the point where it creates the file and puts the first line in but it is showing the drive letter from the first drive and the path of the last drive then I need to know how to make it echo each mapped drive correctly.

<code>
computername = "PLTWIN02"
username = "andersj"
Const HKEY_USERS = &H80000003
Set objWbem = GetObject("winmgmts:")
Set objreg=getobject("winmgmts:{impersonationlevel=impersonate}!\\" & computername & "\root\default:StdRegProv")

lngRtn = objReg.EnumKey(HKEY_USERS, "", arrRegKeys) 'enumerate HKEY_USERS to get all SIDS on remote computer

For Each strKey In arrRegKeys
If UCase(strKey) = ".DEFAULT" Or UCase(Right(strKey, 8)) = "_CLASSES" Then
Else
Set objSID = objWbem.Get("Win32_SID.SID='" & strKey & "'")

If objsid.accountname = username Then 'if the account name of the current sid we're checking matches the accountname we're looking for then do this- -
regpath2enumerate = strkey & "\Network" 'strkey is the SID
objreg.enumkey hkey_users, regpath2enumerate, arrkeynames

If Not (IsEmpty(arrkeynames)) Then
For Each subkey In arrkeynames
regpath = strkey & "\Network\" & subkey
regentry = "RemotePath"
objreg.getstringvalue hkey_users, regpath, regentry, dapath
wscript.echo subkey & ":" & vbtab & dapath
Next
Else
wscript.echo "There are no drive letters for computer " & computername
End If
End If
End If
Next

dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("\\hisjordan\Shared\Mapped\" & username & ".txt", True)
path = filesys.GetAbsolutePathName("\\hisjordan\Shared\Mapped\" & username & ".txt")
getname = filesys.GetFileName(path)
For Each subkey In arrkeynames
filetxt.WriteLine("net use " & subkey & ": """ & dapath & """ /yes")
filetxt.Close
If filesys.FileExists(path) Then
Response.Write ("Your file, '" & getname & "', has been created.")
End If
Next
</code>


Thank you in advance for all your help
 
I modified whats above so it is now giving the drive and path for the first. I just need to figure out how to do the echo properly.

Here is the modified code

computername = "PLTWIN02"
username = "andersj"
Const HKEY_USERS = &H80000003
Set objWbem = GetObject("winmgmts:")
Set objreg=getobject("winmgmts:{impersonationlevel=impersonate}!\\" & computername & "\root\default:StdRegProv")

lngRtn = objReg.EnumKey(HKEY_USERS, "", arrRegKeys) 'enumerate HKEY_USERS to get all SIDS on remote computer

For Each strKey In arrRegKeys
If UCase(strKey) = ".DEFAULT" Or UCase(Right(strKey, 8)) = "_CLASSES" Then
Else
Set objSID = objWbem.Get("Win32_SID.SID='" & strKey & "'")

If objsid.accountname = username Then 'if the account name of the current sid we're checking matches the accountname we're looking for then do this- -
regpath2enumerate = strkey & "\Network" 'strkey is the SID
objreg.enumkey hkey_users, regpath2enumerate, arrkeynames


dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("\\hisjordan\Shared\Mapped\" & username & ".txt", True)
path = filesys.GetAbsolutePathName("\\hisjordan\Shared\Mapped\" & username & ".txt")
getname = filesys.GetFileName(path)

If Not (IsEmpty(arrkeynames)) Then
For Each subkey In arrkeynames
regpath = strkey & "\Network\" & subkey
regentry = "RemotePath"
objreg.getstringvalue hkey_users, regpath, regentry, dapath
wscript.echo filetxt.WriteLine ("net use " & subkey & ": """ & dapath & """ /yes")
filetxt.Close
If filesys.FileExists(path) Then
Response.Write ("Your file, '" & getname & "', has been created.")
End If
Next
Else
wscript.echo "There are no drive letters for computer " & computername
End If
End If
End If
Next

Thanks again.
 

lngRtn = objReg.EnumKey(HKEY_USERS, "", arrRegKeys) 'enumerate HKEY_USERS to get all SIDS on remote computer [red] of users who have logged on since the last reboot[/red]

-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