jhdvy
(Fresh Scripter)
2005-06-16 09:34 PM
Drive Mapping Capture

Is there a way to capture users drive mappings including the drive letter and send the output to a .txt or .ini file?

Thanks


Bryce
(KiX Supporter)
2005-06-16 09:38 PM
Re: Drive Mapping Capture

you could do this...

net use > output.txt


jhdvy
(Fresh Scripter)
2005-06-16 09:46 PM
Re: Drive Mapping Capture

Would rather not do it that way. I thought it could be done through kixtart.

Co
(MM club member)
2005-06-16 09:51 PM
Re: Drive Mapping Capture

What is wrong about it???

This one better???
Code:
shell "cmd /c net use > c:\temp\output.txt"



jhdvy
(Fresh Scripter)
2005-06-16 09:53 PM
Re: Drive Mapping Capture

I thought that kixtart might have build in commands to accomplish this. The output doesn't really work for me.

Les
(KiX Master)
2005-06-16 09:54 PM
Re: Drive Mapping Capture

You can do it all in KiX. Just use RedirectOutput().

maciep
(Korg Regular)
2005-06-16 09:57 PM
Re: Drive Mapping Capture

How about kix and WMI?

Win32_NetworkConnection


jhdvy
(Fresh Scripter)
2005-06-16 09:59 PM
Re: Drive Mapping Capture

Ok, How would I use Win32_NetworkConnection?

Co
(MM club member)
2005-06-16 10:04 PM
Re: Drive Mapping Capture

Sorry, It isn't Kix and I'm to lazy to translate it for you but it does what you want:

Code:

On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_MappedLogicalDisk")

For Each objItem in colItems
Wscript.Echo "Compressed: " & objItem.Compressed
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "Device ID: " & objItem.DeviceID
Wscript.Echo "File System: " & objItem.FileSystem
Wscript.Echo "Free Space: " & objItem.FreeSpace
Wscript.Echo "Maximum Component Length: " & objItem.MaximumComponentLength
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Provider Name: " & objItem.ProviderName
Wscript.Echo "Session ID: " & objItem.SessionID
Wscript.Echo "Size: " & objItem.Size
Wscript.Echo "Supports Disk Quotas: " & objItem.SupportsDiskQuotas
Wscript.Echo "Supports File-Based Compression: " & _
objItem.SupportsFileBasedCompression
Wscript.Echo "Volume Name: " & objItem.VolumeName
Wscript.Echo "Volume Serial Number: " & objItem.VolumeSerialNumber
Wscript.Echo
Next



Co
(MM club member)
2005-06-16 10:06 PM
Re: Drive Mapping Capture

Ooh one thing:


Quote:


List Mapped Network Drives



Description
Retrieves information about mapped network drives. The information returned is similar to that available through the Win32_LogicalDisk class, which retrieves information about the logical disks found on a computer.



Supported Platforms

Windows Server 2003
Yes

Windows XP
Yes

Windows 2000
No

Windows NT 4.0
No

Windows 98
No




jhdvy
(Fresh Scripter)
2005-06-16 10:11 PM
Re: Drive Mapping Capture

Thanks for the script. What do I need to change in this to run it on my local workstation?

Kdyer
(KiX Supporter)
2005-06-16 10:14 PM
Re: Drive Mapping Capture

Here you go..
Code:

CLS
BREAK ON
$strComputer = "."
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2")

$colItems = $objWMIService.ExecQuery("Select * from Win32_MappedLogicalDisk")

For Each $objItem in $colItems
? "Compressed: " + $objItem.Compressed
? "Description: " + $objItem.Description
? "Device ID: " + $objItem.DeviceID
? "File System: " + $objItem.FileSystem
? "Free Space: " + $objItem.FreeSpace
? "Maximum Component Length: " + $objItem.MaximumComponentLength
? "Name: " + $objItem.Name
? "Provider Name: " + $objItem.ProviderName
? "Session ID: " + $objItem.SessionID
? "Size: " + $objItem.Size
? "Supports Disk Quotas: " + $objItem.SupportsDiskQuotas
? "Supports File-Based Compression: " + $objItem.SupportsFileBasedCompression
? "Volume Name: " + $objItem.VolumeName
? "Volume Serial Number: " + $objItem.VolumeSerialNumber
?
Next
get $



Also, you may want to check out WMIQUERY() too.

HTH,

Kent


jhdvy
(Fresh Scripter)
2005-06-16 10:24 PM
Re: Drive Mapping Capture

Looks like this is just what I need. One question though. Why would the Provide Name be blank on most of the drives?

Chris S.
(MM club member)
2005-06-16 10:30 PM
Re: Drive Mapping Capture

Before you go much further, you realize that WIN32_MappedLogicalDisk class is only present on Windows XP or above. This will not work on Windows 2000 or less.

jhdvy
(Fresh Scripter)
2005-06-16 10:32 PM
Re: Drive Mapping Capture

Is there anything that I can use on 2000 devices. Most of our servers are 2000.

Chris S.
(MM club member)
2005-06-16 10:44 PM
Re: Drive Mapping Capture

FSO to the rescue again...

Code:

Dim $fso, $d, $dc
$fso = CreateObject("Scripting.FileSystemObject")
$dc = $fso.Drives
For Each $d in $dc
If $d.DriveType = 3
"Drive Letter: " + $d.DriveLetter ?
" Share Name: " + $d.ShareName ??
EndIf
Next



jhdvy
(Fresh Scripter)
2005-06-16 10:48 PM
Re: Drive Mapping Capture

Thanks you so much. What if I want to store it in an .ini file?

Chris S.
(MM club member)
2005-06-16 10:50 PM
Re: Drive Mapping Capture

Sure, you can use WriteProfileString() to write it to an .ini file.

jhdvy
(Fresh Scripter)
2005-06-16 10:54 PM
Re: Drive Mapping Capture

I know I'm pushing it but would you have an example on how to do that?

Chris S.
(MM club member)
2005-06-16 10:55 PM
Re: Drive Mapping Capture

There is an example in the manual.

Sorry, but I have to go coach my daughter's softball team.


Co
(MM club member)
2005-06-16 10:59 PM
Re: Drive Mapping Capture

Search the board too. There are lots of examples. It is also the way to learn more about Kix..

Good luck!


Co
(MM club member)
2005-06-17 06:43 AM
Re: Drive Mapping Capture

We almost forgot this one:

EnumNetworkConnections() - Creates an Array/List of Network Connections


jhdvy
(Fresh Scripter)
2005-06-17 03:35 PM
Re: Drive Mapping Capture

How do I get an output from the above function? Also, in the fso example, is there a way to label the connection as network connection 1 = j: \\server\share, network connection 2 = m: \\server\share.

Thanks


Chris S.
(MM club member)
2005-06-17 04:03 PM
Re: Drive Mapping Capture

Everything you need to do what you want is there, you just need to put it together. You're asking for "silver platter" code and as volunteers we don't always have the time to put all of the code together for people.

Please understand that I'm not bashing you, just asking you to make the effort to understand the examples provided and put it together.


Les
(KiX Master)
2005-06-17 04:06 PM
Re: Drive Mapping Capture

The function returns the output for you in an array. You just need to do var/string manipulation.

Some of the board regulars don't mind putting code on a silver platter for you, but you may get better results if you put forth an effort and actually try to do some of the coding yourself and then ask for help when you are stuck.


Les
(KiX Master)
2005-06-17 04:09 PM
Re: Drive Mapping Capture

ROFL
I should have hit refresh! Did not realize Chris posted almost the same thing I did. Great minds do think alike.


jhdvy
(Fresh Scripter)
2005-06-30 05:53 PM
Re: Drive Mapping Capture

Ok, I've tried to make this work for about 2 weeks now but haven't had much luck labeling the connection as
network connection1=\\server\share
network connection2=\\server\share

Anyone care to shed some light on how to do this?

Thanks


LonkeroAdministrator
(KiX Master Guru)
2005-06-30 06:20 PM
Re: Drive Mapping Capture

what you mean with label?

Les
(KiX Master)
2005-06-30 06:36 PM
Re: Drive Mapping Capture

jhdvy,
Maybe if you showed us some of your code we might be able to grasp what it is you are trying to do. You have been offered at least four alternatives so far and I havent a clue which one you are working with and what you are trying to do.


NTDOCAdministrator
(KiX Master)
2005-06-30 08:48 PM
Re: Drive Mapping Capture

Well using something like this works, but there are "timing" issues which might prevent the label from working all the time.

MapDrive('T','\\SERVER01\FILESHARE','IT Support',,1,0)

That would place a label of 'IT Support' on the T drive when mapped using the MapDrive UDF

Code:
Function MapDrive($DriveLetter,$UNC,optional $Label,$Icon,$Delete,$Persistent)
Dim $,$D,$Di,$Per,$Shell
$D = Left($DriveLetter,1)
$Di= 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons'
If $Delete
Use $D+':' /DELETE /PERSISTENT
If $Admin
$=DelTree($Di+'\'+$D)
EndIf
EndIf
If $Persistent
Use $D+':' $UNC /PERSISTENT
Else
Use $D+':' $UNC
EndIf
If Not Exist($D+':\') Exit 1 EndIf
If $Label
$Shell=CreateObject("shell.application")
If @ERROR Exit @ERROR EndIf
$Shell.namespace($D+':\').self.name=$Label
EndIf
If $Admin
If $Icon
$=WriteValue($Di+'\'+$D+'\DefaultIcon','',$Icon,REG_SZ)
EndIf
EndIf
Exit @ERROR
EndFunction


 


LonkeroAdministrator
(KiX Master Guru)
2005-07-01 12:12 AM
Re: Drive Mapping Capture

hmm...
that would be, if he really means the real label.
I was more thinking like he didn't know how to give a dynamic name to a variable.


Les
(KiX Master)
2005-07-01 12:17 AM
Re: Drive Mapping Capture

My guess is he wants to put them in as keys in an INI file. Talk about three divergent interpretations!

StarwarsKid
(Seasoned Scripter)
2005-07-01 01:12 AM
Re: Drive Mapping Capture

NTDOC, Could you clarify the timing issue you mentioned? Is there a way to prevent it? (I HOPE this doesn't qualify as hijaaking this post! )

jhdvy
(Fresh Scripter)
2005-07-01 06:46 PM
Re: Drive Mapping Capture

All I would like to be able to do is list each network drive in an .ini file.
Example.. If I have 3 drives mapped J, K and L, I would like to write it to my .ini file as
network drive1=J \\server\share
netowrk drive2=K \\server\share
network drive3=L \\server\share

I'm using the fso solution to capture the mappings.
Dim $fso, $d, $dc
$fso = CreateObject("Scripting.FileSystemObject")
$dc = $fso.Drives
For Each $d In $dc
If $d.DriveType = 3
$d.DriveLetter "=" + $d.ShareName?
EndIf
Next


Chris S.
(MM club member)
2005-07-01 07:16 PM
Re: Drive Mapping Capture

This works for me...

Code:

Dim $fso, $d, $dc
$fso = CreateObject("Scripting.FileSystemObject")
$dc = $fso.Drives
For Each $d in $dc
If $d.DriveType = 3
If WriteProfileString(@SCRIPTDIR+"\netdrives.ini","DRIVES",$d.DriveLetter,$d.ShareName)
"Error: " + @ERROR + ' | ' + @SERROR ?
EndIf
EndIf
Next



Sealeopard
(KiX Master)
2005-07-01 11:45 PM
Re: Drive Mapping Capture

There are a couple of MAPDRIVE() UDFs and a LABEL() UDF that enable you to apply custom labels to drive mappings.

NTDOCAdministrator
(KiX Master)
2005-07-02 08:40 AM
Re: Drive Mapping Capture

Think you missed what he was wanting Jens.

Code from Chris should handle what it appears to be he's looking for.


Sealeopard
(KiX Master)
2005-07-02 02:32 PM
Re: Drive Mapping Capture

Yeah, guess so.

Les
(KiX Master)
2005-07-02 03:31 PM
Re: Drive Mapping Capture

Eh.. at least one of us interpreted it right.

jhdvy
(Fresh Scripter)
2005-07-15 02:32 PM
Re: Drive Mapping Capture

Here is what I have so far. I doesn't look too good but it works. Any recommendations are appreciated. Please go easy on me I'm fairly new to kix.
Code:
If @DOS = "4.0"
GoTo "END"
Else
If @DOS = "5.0" OR "5.01"
GoTo "BEGIN"
EndIf
EndIf

:Begin
If NOT Exist ("\\server\share\" + @WkSta + ".ini")
GoTo "Step1"
Else
GoTo "Step2"
EndIf


:Step1
?"Getting Hardware and Software Inventory. Please wait......"
$wsinfofile = "\\server\share\" + @WkSta + ".ini"
$rc = WriteProfileString("$WSInfoFile","WsInfo","User Name","@FullName")
$rc = WriteProfileString("$WSInfoFile","WsInfo","UserID","@Userid")
$rc = WriteProfileString("$WSInfoFile","WsInfo","WS Domain","@DOMAIN")
$rc = WriteProfileString("$WSInfoFile","WsInfo","Login Domain","@LDOMAIN")
$rc = WriteProfileString("$WSInfoFile","WsInfo","WsName","@WkSta")
$rc = WriteProfileString("$WSInfoFile","WsInfo","IPAddress","@ipaddress0")
$rc = WriteProfileString("$WSInfoFile","WsInfo","Date","@month @mdayno @year @time")

If RedirectOutput("\\server\share\" + @WkSta + ".ini") = 0
? "The following is System and Hardware Info:"
? "System Name = "WMIQuery("CSName","Win32_OperatingSystem")
? "OS Name = "WMIQuery("Caption","Win32_OperatingSystem")
? "Manufacturer = "WMIQuery("Manufacturer","Win32_OperatingSystem")
? "OS Version Number = "WMIQuery("Version","Win32_OperatingSystem")
? "OS Build Number = "WMIQuery("BuildNumber","Win32_OperatingSystem")
? "OS Build Type = "WMIQuery("BuildType","Win32_OperatingSystem")
? "Language = "WMIQuery("OSLanguage","Win32_OperatingSystem")
? "Service Pack = "WMIQuery("CSDVersion","Win32_OperatingSystem")
? "Boot Device = "WMIQuery("BootDevice","Win32_OperatingSystem")
? "System Device = "WMIQuery("SystemDevice","Win32_OperatingSystem")
? "Windows Directory = "WMIQuery("WindowsDirectory","Win32_OperatingSystem")
? "System Directory = "WMIQuery("SystemDirectory","Win32_OperatingSystem")
? "Install Date = "WMIQuery("InstallDate","Win32_OperatingSystem")
? "Last Boot Time = "WMIQuery("LastBootupTime","Win32_OperatingSystem")
? "Registered User = "WMIQuery("RegisteredUser","Win32_OperatingSystem")
? "Registered Organization = "WMIQuery("Organization","Win32_OperatingSystem")
? "OS Serial Number = "WMIQuery("SerialNumber","Win32_OperatingSystem")
? "System Manufacturer is = "WMIQuery("Manufacturer","Win32_ComputerSystem")
? "System Model is = "WMIQuery("Model","Win32_ComputerSystem")
? "System Serial Number is = "WMIQuery("SerialNumber","Win32_BIOS")
? "System BIOS Version is = "WMIQuery("SMBIOSBIOSVersion","Win32_BIOS")
? "System BIOS Date is = "WMIQuery("Version","Win32_BIOS")
? "CPU Manufacturer: = "WMIQuery("manufacturer","Win32_Processor")
? "Description: = "WMIQuery("description","Win32_Processor")
? "CPU Speed is = "WMIQuery("CurrentClockSpeed","Win32_Processor") " Mhz"
? "Maximum Clock Speed = "WMIQuery("maxclockspeed","Win32_Processor") " Mhz"
? "L2 Cache Size: = "WMIQuery("l2cachesize","Win32_Processor")
? "L2 Cache Speed: = "WMIQuery("l2cachespeed","Win32_Processor")
? "Family: = "WMIQuery("family","Win32_Processor")
? "Level: = "WMIQuery("level","Win32_Processor")
? "Stepping: = "WMIQuery("stepping","Win32_Processor")
? "Device ID: = "WMIQuery("deviceid","Win32_Processor")
? "Unique ID: = "WMIQuery("uniqueid","Win32_Processor")
? "System Memory = "Val(WMIQuery("TotalPhysicalMemory","Win32_LogicalMemoryConfiguration"))/1024 " MB"
For Each $dimm In Split(WMIQuery("Capacity","Win32_PhysicalMemory"),"|")
? "Dimm Size = "Val($dimm) / 1048576 " MB"
Next
;? "Disk Name/s = "WMIQuery("name","Win32_LogicalDisk")
;? "Volume Name = "WMIQuery("volumename","Win32_LogicalDisk")" MB"
? "Size = "WMIQuery("size","Win32_diskdrive") " MB"
? "File System = "WMIQuery("filesystem","Win32_diskdrive")
;? "Free Space = "WMIQuery("freespace","Win32_LogicalDisk")" MB"
? "Video Card is = "WMIQuery("Description","Win32_VideoController")
? "Video Res is = "WMIQuery("VideoModeDescription","Win32_VideoController")
? "Modem is = "WMIQuery("Description","Win32_POTSModem")
;for each $ptr in Split(WMIQuery("Name","Win32_printer"),"|")
; ? "Connected Printer is = "$ptr
;next
;for each $nic in Split(WMIQuery("ProductName","Win32_NetworkAdapter"),"|")
; if instr($nic,"miniport")=0 and instr($nic,"RAS")=0 and instr($nic,"Parallel")=0
; ? "Network Card is = "$nic
; endif
;next

?"Network Drives"
?
Dim $fso, $d, $dc
$fso = CreateObject("Scripting.FileSystemObject")
$dc = $fso.Drives
For Each $d In $dc
If $d.DriveType = 3
$d.DriveLetter "=" + $d.ShareName?
EndIf
Next

?'The following is Software Info:'
$InstalledSoftwareArray=GetSoftwareList(1)
For Each $element In $InstalledSoftwareArray
?$element
Next

Function GetSoftwareList(OPTIONAL $Sort)
; Author: ScriptLogic Corporation
; Last revised: 16-nov-2001
; Optional parameter: sort
; if 0 (or not supplied), no sorting of list is done.
; if 1, results are sorted alphabetically, ascending order
; Note: If sorting is requested, this function then has a
; dependency on the Asort( ) UDF.
Dim $ArrayIndex, $EnumIndex, $Component, $DN, $RegKey, $SwArray[200]
$RegKey='HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall'
$EnumIndex=0
$ArrayIndex=0
:gisloop
$Component=EnumKey($RegKey, $EnumIndex)
If NOT @Error
;if not (len($Component)=7 and left($Component,1)='Q')
; above line excludes hotfixes from listing
If NOT (0+ReadValue($RegKey+'\'+$Component,'SystemComponent'))
$DN=ReadValue($RegKey+'\'+$Component,'DisplayName')
If $DN
$SwArray[$ArrayIndex]=$DN
$ArrayIndex=$ArrayIndex+1
EndIf
EndIf
$EnumIndex=$EnumIndex+1
GoTo gisloop
;endif
EndIf
ReDim preserve $SwArray[$ArrayIndex]
If $Sort
$GetSoftwareList=Asort($SwArray)
Else
$GetSoftwareList=$SwArray
EndIf
EndFunction

Function ASort($array, OPTIONAL $order)
; sort order: 0 = ascending, 1 = decending
Dim $index, $x, $y, $tmp, $changed
$Asort=$array
$order=0+$order
Do
$changed=0
For $index = 0 to Ubound($asort)-1
$x=$asort[$index]
$y=$asort[$index+1]
If ($x > $y AND 1-$order) OR ($x < $y AND $order)
$tmp=$x
$asort[$index]=$y
$asort[$index+1]=$tmp
$changed=1
EndIf
Next
Until $changed=0
EndFunction


Function WMIQuery($what,$where,)
Dim $strQuery, $objEnumerator, $value
$strQuery = "Select $what From $where"
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//@WKSTA")
$objEnumerator = $SystemSet.ExecQuery($strQuery)
For Each $objInstance In $objEnumerator
If @Error = 0 AND $objInstance <> ""
$=Execute("$$value = $$objInstance.$what")
$WMIQuery="$value"+"|"+"$WMIQuery"
EndIf
Next
$WMIQuery=Left($WMIQuery,Len($WMIQuery)-1)
Exit @error
EndFunction
$computer = @wksta
;? WMIQuery2("Services on","Win32_Service")
;? WMIQuery2("Processes on","Win32_Process")
Function WMIQuery2($what,$where,)
$wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!//" + $computer + "/root/cimv2")
$list = ""
$objs = $wmi.instancesof($where)
For Each $obj In $objs
$list = $list + $obj.description + Chr(13) + Chr(10)
Next
$list=Left($list, Len($list))
?$what +" "+ $computer + Chr(13) + Chr(10) + $list
EndFunction
If RedirectOutput("")=0
EndIf


:Step2
$wsinfofile = "\\server\share\" + @WkSta + ".ini"
$rc = WriteProfileString("$WSInfoFile","WsInfo","User Name","@FullName")
$rc = WriteProfileString("$WSInfoFile","WsInfo","UserID","@Userid")
$rc = WriteProfileString("$WSInfoFile","WsInfo","WS Domain","@DOMAIN")
$rc = WriteProfileString("$WSInfoFile","WsInfo","Login Domain","@LDOMAIN")
$rc = WriteProfileString("$WSInfoFile","WsInfo","WsName","@WkSta")
$rc = WriteProfileString("$WSInfoFile","WsInfo","IPAddress","@ipaddress0")
$rc = WriteProfileString("$WSInfoFile","WsInfo","Date","@month @mdayno @year @time")

:END



NTDOCAdministrator
(KiX Master)
2005-07-15 07:40 PM
Re: Drive Mapping Capture

Okay, I'll be easy for now


Please review your coding method and try to remove the use of GOTO which if coded better is not needed.