maqleod Posted November 3, 2008 Posted November 3, 2008 (edited) how do you find out if a current connection is persistant or what user the drive was mapped under? Edited November 3, 2008 by maqleod [u]You can download my projects at:[/u] Pulsar Software
jerem488 Posted November 3, 2008 Posted November 3, 2008 You want know if a mapped drive is persistant or not ??? Qui ose gagneWho Dares Win[left]CyberExploit[/left]
weaponx Posted November 3, 2008 Posted November 3, 2008 http://www.experts-exchange.com/OS/Microso...Q_21515073.html
rudi Posted November 3, 2008 Posted November 3, 2008 Hi.http://www.experts-exchange.com/OS/Microso...Q_21515073.htmlWould you mind to post the solution here rather than pointing to a "closed group" system like ExEx, please?I personaly dislike this kind of platforms, that encourage you to start with a so called "free", teaser trial: IMHO knowledge should be permanently free for all those, that are able and willing to read!Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE!
weaponx Posted November 3, 2008 Posted November 3, 2008 Sorry, it works if you click the link through Google.Can I ask why you're looking for that particular attribute?You're going to make me prove myself wrong aren't you? :^ )Okay - here's what I have found...If you map a drive "with" persistent connections, it appears in the registry under the key:HKCU\Network\<DriveLetter> (obviously, where drive letter is the mapped drive).If you don't map persistently, the drive letter will simply not appear there, and thus won't be remembered after a reboot.Now, if you're looking to pull that information automated - if you have a copy of the W2k Resource Kit, you can use REG.EXE to retrieve this info.reg query hkcu\network Would reveal the persistent mapped drives.If, however, you don't have access to reg.exe, you can download it here: http://www.dynawell.com/reskit/microsoft/win2000/reg.zipThanx for the challenge! ;^ )
rudi Posted November 3, 2008 Posted November 3, 2008 HiSorry, it works if you click the link through Google.Okay - here's what I have found...If you map a drive "with" persistent connections, it appears in the registry under the key:HKCU\Network\<DriveLetter> (obviously, where drive letter is the mapped drive).If you don't map persistently, the drive letter will simply not appear there, and thus won't be remembered after a reboot.Interesting, thanks.I'm just wondering if there is a possiblity to create computer persistent mappings. (HKLM rather than HKCU)I'll check later this week, I have to leave for a 400km foggy car drive right now...Regards, Rudi.Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE!
weaponx Posted November 3, 2008 Posted November 3, 2008 http://windowsitpro.com/article/articleid/...cripts-etc.html
maqleod Posted November 7, 2008 Author Posted November 7, 2008 hmm, I was really hoping for just a simpler method, such as querying a file or reg key for a 1 or 0... basically, I am trying to write a share manager and in the listview I want to show each mapped drive, whether it is persistent or not, and the user who is connected to it. I also will have a list of local shares with various information, some which I might ask for help at a later time when i get that far. In any case, so you can get a better idea I'm including what little I have so far of the source: expandcollapse popup#include <GuiConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinNet.au3> #include <NetShare.au3> Global $name, $main, $maps $name = "Share Manager v0.1" main() Func main() Local $i, $drives, $shared, $path, $user, $addmap, $editmap, $deletemap, $shares, $addshare, $editshare, $deleteshare, $help, $close, $msg $drives = DriveGetDrive("Network") $shared = _Net_Share_ShareEnum() $main = GUICreate($name, 500, 500, -1, -1, -1, -1) GUICtrlCreateLabel("Maps", 5, 5, 50, 20, -1, -1) $maps = GUICtrlCreateListView("Drive|Map Location |Persistant|User", 5, 25, 490, 160, -1, -1) For $i = 1 To $drives[0] $path = DriveMapGet($drives[$i]) $user = _WinNet_GetUser($path) GUICtrlCreateListViewItem($drives[$i] & "|" & $path & "|" & "" & "|" & $user, $maps) Next $addmap = GUICtrlCreateButton("Add Map", 25, 195, 75, 25, -1, -1) $editmap = GUICtrlCreateButton("Edit Map", 110, 195, 75, 25, -1, -1) $deletemap = GUICtrlCreateButton("Delete Map", 195, 195, 75, 25, -1, -1) GUICtrlCreateLabel("Shares", 5, 235, 50, 20, -1, -1) $shares = GUICtrlCreateListView("Share Name |Share Location ", 5, 255, 490, 160, -1, -1) For $i = 1 To $shared[0][0] GUICtrlCreateListViewItem($shared[$i][0] & "|" & $shared[$i][6], $shares) Next $addshare = GUICtrlCreateButton("Add Share", 25, 425, 75, 25, -1, -1) $editshare = GUICtrlCreateButton("Edit Share", 110, 425, 75, 25, -1, -1) $deleteshare = GUICtrlCreateButton("Delete Share", 195, 425, 75, 25, -1, -1) $help = GUICtrlCreateButton("?", 380, 470, 25, 25, -1, -1) $close = GUICtrlCreateButton("Close", 410, 470, 75, 25, -1, -1) GUISetState() Do $msg = GUIGetMsg() If $msg = $addmap Then AddMap() EndIf If $msg = $editmap Then EditMap() EndIf If $msg = $deletemap Then DelMap() EndIf If $msg = $addshare Then AddShare() EndIf If $msg = $editshare Then EditShare() EndIf If $msg = $deleteshare Then DelShare() EndIf If $msg = $help Then Help() EndIf If $msg = $close Then ExitLoop EndIf Until $msg = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>main Func AddMap() Local $addmapgui,$letter,$path,$findpath,$persistant,$user,$add,$cancel,$msg,$persist,$adddrive $addmapgui = GUICreate("Add Mapped Drive", 250, 150, -1, -1, -1, -1, $main) GUICtrlCreateLabel("Letter:", 5, 5, 60, 20, -1, -1) $letter = GUICtrlCreateCombo("F:", 5, 25, 40, 20, -1, -1) GUICtrlCreateLabel("Path:", 55, 5, 80, 20, -1, -1) $path = GUICtrlCreateInput("", 55, 25, 165, 20, -1, -1) $findpath = GUICtrlCreateButton("...", 220, 23, 25, 25, -1, -1);need to implement $persistant = GUICtrlCreateCheckbox("Persistant", 65, 50, 65, 20, -1, -1);need to implement $user = GUICtrlCreateCheckbox("Different User", 145, 50, 90, 20, -1, -1);need to implement $add = GUICtrlCreateButton("Add", 40, 95, 75, 25, -1, -1) $cancel = GUICtrlCreateButton("Cancel", 140, 95, 75, 25, -1, -1) GUISetState() Do $msg = GUIGetMsg() If $msg = $add Then If GUICtrlRead($persistant) = $GUI_CHECKED Then $persist = 1 Else $persist = 0 EndIf If GUICtrlRead($user) = $GUI_CHECKED Then $userinfo = GetUser($addmapgui) $adddrive = DriveMapAdd($letter, $path, $persist,$userinfo[0],$userinfo[1]) Else $adddrive = DriveMapAdd($letter, $path, $persist) EndIf If $adddrive = 1 Then GUICtrlCreateListViewItem($letter & "|" & $path, $maps) ExitLoop Else MsgBox(64, "Error", "Drive Map Failed.") EndIf EndIf If $msg = $cancel Then ExitLoop EndIf Until $msg = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>AddMap Func EditMap() $editmapgui = GUICreate("Edit Mapped Drive", 250, 150, -1, -1, -1, -1, $main) GUISetState() Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>EditMap Func DelMap() $delmapgui = GUICreate("Delete Mapped Drive", 250, 150, -1, -1, -1, -1, $main) GUISetState() Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>DelMap Func AddShare() $addshgui = GUICreate("Add Share", 250, 150, -1, -1, -1, -1, $main) GUISetState() Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>AddShare Func EditShare() $editshgui = GUICreate("Edit Share", 250, 150, -1, -1, -1, -1, $main) GUISetState() Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>EditShare Func DelShare() $delshgui = GUICreate("Delete Share", 250, 150, -1, -1, -1, -1, $main) GUISetState() Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>DelShare Func Help() $helpgui = GUICreate("Help", 250, 150, -1, -1, -1, -1, $main) GUISetState() Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Help Func GetUser($parent) Local $userinfo[2],$usergui,$username,$password,$ok $userinfo[0] = "" $userinfo[1] = "" $usergui = GUICreate("User", 125, 150, -1, -1, -1, -1, $parent) GuiCtrlCreateLabel("User:",5,5,50,20,-1,-1) $username = GuiCtrlCreateInput("",5,25,100,20,-1,-1) GuiCtrlCreateLabel("Password:",5,50,50,20,-1,-1) $password = GuiCtrlCreateInput("",5,70,100,20,$ES_PASSWORD,-1) $ok = GuiCtrlCreateButton("OK",28,100,75,25,-1,-1) GUISetState() Do $msg = GUIGetMsg() If $msg = $ok Then $userinfo[0] = GuiCtrlRead($username) $userinfo[1] = GuiCtrlRead($password) ExitLoop EndIf Until $msg = $GUI_EVENT_CLOSE GUIDelete() Return $userinfo EndFunc ;==>GetUser [u]You can download my projects at:[/u] Pulsar Software
ResNullius Posted November 7, 2008 Posted November 7, 2008 (edited) how do you find out if a current connection is persistant or what user the drive was mapped under?WMI can tell you (and a lot of other info too) expandcollapse popupMsgBox(0, "", _GetMappedDriveInfo("x:")) Func _GetMappedDriveInfo($DriveLetter) $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output = "" $Output &= "Computer: " & $strComputer & @CRLF $Output &= "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkConnection WHERE LOCALNAME = '" & $DriveLetter & "'", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems ;$Output &= "AccessMask: " & $objItem.AccessMask & @CRLF ;$Output &= "Caption: " & $objItem.Caption & @CRLF ;$Output &= "Comment: " & $objItem.Comment & @CRLF $Output &= "ConnectionState: " & $objItem.ConnectionState & @CRLF $Output &= "ConnectionType: " & $objItem.ConnectionType & @CRLF ;$Output &= "Description: " & $objItem.Description & @CRLF ;$Output &= "DisplayType: " & $objItem.DisplayType & @CRLF ;$Output &= "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF $Output &= "LocalName: " & $objItem.LocalName & @CRLF $Output &= "Name: " & $objItem.Name & @CRLF If $objItem.Persistent = 0 Then $Output &= "Persistent: NO" & @CRLF Else $Output &= "Persistent: YES" & @CRLF EndIf ;$Output &= "ProviderName: " & $objItem.ProviderName & @CRLF ;$Output &= "RemoteName: " & $objItem.RemoteName & @CRLF $Output &= "RemotePath: " & $objItem.RemotePath & @CRLF ;$Output &= "ResourceType: " & $objItem.ResourceType & @CRLF ;$Output &= "Status: " & $objItem.Status & @CRLF ;$Output &= "UserName: " & $objItem.UserName & @CRLF Next Else MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_NetworkConnection") EndIf Return $Output EndFunc ;==>_GetMappedDriveInfo Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2)) EndFunc ;==>WMIDateStringToDate (Note: thanks to SvenP's AI Scriptomatic!) Edited November 7, 2008 by ResNullius
ResNullius Posted November 8, 2008 Posted November 8, 2008 (edited) Actually, there is a registry entry you can check!All persistent mappings end up under [HKEY_CURRENT_USER\Network] (Windows 2000/XP anyway)example for drive mapped as X:[HKEY_CURRENT_USER\Network\X] "RemotePath"="\\\\SERVER1\\JUNK" "UserName"="" "ProviderName"="Microsoft Windows Network" "ProviderType"=dword:00020000 "ConnectionType"=dword:00000001From what I can tell, all 5 of the entries must be present for the drive persistence to register as positive.Edit: So here's a function you could drop into your script$drives = DriveGetDrive("Network") For $i = 1 To $drives[0] MsgBox(0,"Persistent",$drives[$i] & " = " & _IsMapPersistent($Drives[$i])) Next Func _IsMapPersistent($MappedDrive) $mapErr = 0 $MappedDrive = StringReplace($MappedDrive,":","");get rid of the Colon if passed If Not StringRegExp($MappedDrive,"(?i)\A[a-z]{1}\z") then SetError(-1); no valid drive letter passed Return EndIf $RemotePath = RegRead("HKEY_CURRENT_USER\Network\" & $MappedDrive, "RemotePath") $mapErr += @ERROR $UserName = RegRead("HKEY_CURRENT_USER\Network\" & $MappedDrive, "UserName") $mapErr += @ERROR $ProviderName = RegRead("HKEY_CURRENT_USER\Network\" & $MappedDrive, "ProviderName") $mapErr += @ERROR $ProviderType = RegRead("HKEY_CURRENT_USER\Network\" & $MappedDrive, "ProviderType") $mapErr += @ERROR $ConnectionType = RegRead("HKEY_CURRENT_USER\Network\" & $MappedDrive, "ConnectionType") $mapErr += @ERROR If $mapErr then Return False Else Return TRUE EndIf EndFuncI'm sure there are other tests you could do on the ProviderType/ConnectionType to make sure they're legitimate enteries, but this should be a start. Edited November 8, 2008 by ResNullius
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now