Jump to content

network mappings on remote PC


gcue
 Share

Recommended Posts

hello,

im trying to get the network drive mappings on a remote PC.

im using psexec to run nd.exe (nd.exe is another autoit script shown below)

nd.exe:

$file = "c:\temp\maps.txt"
FileDelete($file)

$drvs = DriveGetDrive( "network" )
if @error Then
    FileWriteLine($file, "No Network Drives Found.")
else
    For $i = 1 to $drvs[0]              
        FileWriteLine($file, $drvs[$i] & "=" & DriveMapGet($drvs[$i]))
    Next
EndIfoÝ÷ Ú*îØb²Ú-¯+h­æ¶«zË¥¶Ç"²ÈZ­çZ±Í7é«­¢+ÙIÕ¹]¥Ð¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈíÁÍá¹áÅÕ½ÐìµÀìÅÕ½ÐìÀäÈìÀäÈìÅÕ½ÐìµÀì½µÁÕÑɹµµÀìÅÕ½Ðìµµ¤èÀäÈíѵÀÀäÈí¹¹áÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì°M]}!%¤)}¥±IQ½ÉÉä ÅÕ½ÐìÀäÈìÀäÈìÅÕ½ÐìµÀì½µÁÕÑɹµµÀìÅÕ½ÐìÀäÈíÀÌØìÀäÈíѵÀÀäÈíµÁ̹ÑáÐÅÕ½Ðì°ÀÌØíµÁÁ¥¹Ì¤)}ÉÉå¥ÍÁ±ä ÀÌØíµÁÁ¥¹Ì°ÅÕ½Ðí9ÑݽɬɥÙ5ÁÁ¥¹ÌÅÕ½Ðì

i always get the same results "No Network Drives Found" *sigh* I know it has to do with the way im running psexec because nd.exe itself works. i;ve also tried specifying -u username and -p password - no dice

Link to comment
Share on other sites

Well if nd is already on there and when you run psexec and you get "No Network Drives Found" then psexec is obviously doing its job by executing the exe. That's all its supposed to do. It's not psexec's fault that nd isn't finding any network drives.

Also what does -d do in psexec?

Edited by SoulA
Link to comment
Share on other sites

You could use the "NET" command with runDOS

interesting solution..

locally the command is "net use" and it shows me a listing of my mappings and mapped paths

i dont see how i can get these results for the remote pc - hmm

Link to comment
Share on other sites

So if you run nd on that machine without doing it remotely through psexec the text file is populated with these network drives or no? I'm trying to figure out if it is a problem with nd or with psexec.

yep

Link to comment
Share on other sites

NET USE has a "\\computername\sharename" parameter, have you tried that?

NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
        [/USER:[domainname\]username]
        [/USER:[dotted domain name\]username]
        [/USER:[username@dotted domain name]
        [/SMARTCARD]
        [/SAVECRED]
        [[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

NET USE [/PERSISTENT:{YES | NO}]

i havent been able to figure out either way.. using NET nor psexec...

this is killing me!!!

Link to comment
Share on other sites

NET USE has a "\\computername\sharename" parameter, have you tried that?

NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
        [/USER:[domainname\]username]
        [/USER:[dotted domain name\]username]
        [/USER:[username@dotted domain name]
        [/SMARTCARD]
        [/SAVECRED]
        [[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

NET USE [/PERSISTENT:{YES | NO}]
thats if you want to map a drive to that sharename

im trying to get the network drive mappings for a remote PC

thanks tho

Link to comment
Share on other sites

You haven't stated what version of Windows you're using, but on any version since Windows 2000 drive mapping is per-profile, so you'd have to be running your script in the user-space of the desired user to see their drive mapping. Since PSEXEC uses a service on the remote end to do its dirty-work, I'll hazard a guess that your script is being run as the system user, which has no drive mapping and which would explain your results.

You might try adapting your remote-end script to run a child process as the desired user, either a NET USE command or another AutoIt script.

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

sorry forgot to mention - using windows XP.

thanks =)

Hi,

I also think the problem is due to psexec running as system, this means it can't see any of the user's mapped drives. This is a bit clumsy but you could:

Use psexec to add the client side file to the run section of the registry on the client pc, this way it will run as the user, so will see networked drives.

Alter the client side file so that it only runs when it sees a particular marker file on the hard drive, if the marker file is not there it sleeps for 5 minutes? and checks again. If the marker file is there it logs all the drives, writes this info somewhere or sends you a message, then deletes the marker file.

Now when you need to it to run on the client use psexec or net use to place the marker file on the client PC.

Cheers,

Stephen

Link to comment
Share on other sites

Use WMI...just change "localhost" to the remote machine name or IP.

You really only need to return DeviceId and ProviderName.

$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_LogicalDisk WHERE DriveType = 4", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output &= "Access: " & $objItem.Access & @CRLF
      $Output &= "Availability: " & $objItem.Availability & @CRLF
      $Output &= "BlockSize: " & $objItem.BlockSize & @CRLF
      $Output &= "Caption: " & $objItem.Caption & @CRLF
      $Output &= "Compressed: " & $objItem.Compressed & @CRLF
      $Output &= "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF
      $Output &= "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF
      $Output &= "CreationClassName: " & $objItem.CreationClassName & @CRLF
      $Output &= "Description: " & $objItem.Description & @CRLF
      $Output &= "DeviceID: " & $objItem.DeviceID & @CRLF
      $Output &= "DriveType: " & $objItem.DriveType & @CRLF
      $Output &= "ErrorCleared: " & $objItem.ErrorCleared & @CRLF
      $Output &= "ErrorDescription: " & $objItem.ErrorDescription & @CRLF
      $Output &= "ErrorMethodology: " & $objItem.ErrorMethodology & @CRLF
      $Output &= "FileSystem: " & $objItem.FileSystem & @CRLF
      $Output &= "FreeSpace: " & $objItem.FreeSpace & @CRLF
      $Output &= "LastErrorCode: " & $objItem.LastErrorCode & @CRLF
      $Output &= "MaximumComponentLength: " & $objItem.MaximumComponentLength & @CRLF
      $Output &= "MediaType: " & $objItem.MediaType & @CRLF
      $Output &= "Name: " & $objItem.Name & @CRLF
      $Output &= "NumberOfBlocks: " & $objItem.NumberOfBlocks & @CRLF
      $Output &= "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF
      $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0)
      $Output &= "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF
      $Output &= "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF
      $Output &= "ProviderName: " & $objItem.ProviderName & @CRLF
      $Output &= "Purpose: " & $objItem.Purpose & @CRLF
      $Output &= "QuotasDisabled: " & $objItem.QuotasDisabled & @CRLF
      $Output &= "QuotasIncomplete: " & $objItem.QuotasIncomplete & @CRLF
      $Output &= "QuotasRebuilding: " & $objItem.QuotasRebuilding & @CRLF
      $Output &= "Size: " & $objItem.Size & @CRLF
      $Output &= "Status: " & $objItem.Status & @CRLF
      $Output &= "StatusInfo: " & $objItem.StatusInfo & @CRLF
      $Output &= "SupportsDiskQuotas: " & $objItem.SupportsDiskQuotas & @CRLF
      $Output &= "SupportsFileBasedCompression: " & $objItem.SupportsFileBasedCompression & @CRLF
      $Output &= "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF
      $Output &= "SystemName: " & $objItem.SystemName & @CRLF
      $Output &= "VolumeDirty: " & $objItem.VolumeDirty & @CRLF
      $Output &= "VolumeName: " & $objItem.VolumeName & @CRLF
      $Output &= "VolumeSerialNumber: " & $objItem.VolumeSerialNumber & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_LogicalDisk" )
Endif
Link to comment
Share on other sites

neat!

i cant get it to work if its not localhost tho..even on other machines where I am logged in with the same credentials

i tried a few remote pcs (where i am an admin) no dice - dont even get teh msgbox error at the end.. weird.

putting in the hostname as i do with other wmi scripts

i also tried putting in this:

"winmgmts:{impersonationLevel=impersonate,(Security)}!\\" (which looks like its back to square one - using "security" *sigh*)

this is exaclty what i need - just need it to run on remote pcs =/

Edited by gcue
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...