Radimus
(KiX Supporter)
2002-12-03 03:41 PM
remotely create mapped drive

I'd like to be able to map a drive for a user remotely... not with a client side script.

ideas??


JochenAdministrator
(KiX Supporter)
2002-12-03 03:54 PM
Re: remotely create mapped drive

What comes to my mind here would be rcmd , but hey we are in COM forum [Roll Eyes]

JochenAdministrator
(KiX Supporter)
2002-12-03 04:00 PM
Re: remotely create mapped drive

thinking it a bit farther, I must say that you can automate the whole thing form the installation of rcmd through the unistall of it ... No COM at all, but a solution

JochenAdministrator
(KiX Supporter)
2002-12-03 04:08 PM
Re: remotely create mapped drive

hmmm ... well, you could wrap this thing in a kixform ?

Chris S.
(MM club member)
2002-12-03 04:21 PM
Re: remotely create mapped drive

You could use WMI to remotely execute a process on the target PC to 'net use' a share. Done it, yes I have.

Radimus
(KiX Supporter)
2002-12-03 04:24 PM
Re: remotely create mapped drive

would you need the user's account/PW?

and it would be in the user's context?

WMI and network stuff is.. difficult..


Chris S.
(MM club member)
2002-12-03 04:32 PM
Re: remotely create mapped drive

I can't answer that. I mapped a drive on a test PC, on which I was logged-on to.

JochenAdministrator
(KiX Supporter)
2002-12-03 04:39 PM
Re: remotely create mapped drive

Rad,

how about taking this as exercise in creating a costum form asking for remote pc / drive letter / path to share having the option to remove rcmd afterwards
All with a nice and shiny User Interface ?


Radimus
(KiX Supporter)
2002-12-03 06:14 PM
Re: remotely create mapped drive

That is kind of what I'm doing...

refer to My new Project...


Radimus
(KiX Supporter)
2002-12-03 09:58 PM
Re: remotely create mapped drive

I'm trying this, but the service isn't working...

code:
	$destdir="\\$name\c$$\Winnt"
copy "$tools\rcmdsvc.exe" "$destdir"
shell "cmd /c $tools\xnet.exe INSTALL \\$name\Rcmd /b:C:\WINNT\rcmdsvc.EXE /u:@domain\@userid /p:$password"
shell "cmd /c $tools\xnet.exe start \\$name\Rcmd"
shell "cmd /c $tools\rcmd.exe \\$name net use $dl: $svrpath"
shell "cmd /c $tools\xnet.exe stop \\$name\Rcmd"
shell "cmd /c $tools\xnet.exe remove \\$name\Rcmd /y"
del "$destdir\rcmdsvc.exe"

quote:
Service installed successfully.

Starting Rcmd
Request completed successfully.
Error - Failed to connect to <\\wheelerc_2nd>, system not found or service not a
ctive
Stopping Rcmd
Stopping the service failed...[1062 / service not active]

Service successfully removed.



Howard Bullock
(KiX Supporter)
2002-12-03 10:36 PM
Re: remotely create mapped drive

First item is that I believe you are calling it by the wrong name.
code:
running          RemoteCmd                        Remote Command Server

{edit}

Also, I have never seen this service run as anything other than the "system" account.

when a user connects the security context of the person connecting is used, but since RemoteCmd is running as system, you will have to supply a user and paswword to connect a drive.

[ 03. December 2002, 22:42: Message edited by: Howard Bullock ]


JochenAdministrator
(KiX Supporter)
2002-12-04 09:43 AM
Re: remotely create mapped drive

Rad,

you might want to copy (steal) code in Bryce's excellent rcmd installer script [Big Grin]


JochenAdministrator
(KiX Supporter)
2002-12-04 09:45 AM
Re: remotely create mapped drive

Also there are different issues in returning errorlevels of rcmd commands :

it returns 1 only if the rcmd session was finished successfully but not the errorlevel of the command (this was to be returned with a trick i can't remember right now)


Radimus
(KiX Supporter)
2002-12-05 04:30 PM
Re: remotely create mapped drive

ok... after ripping Bryce's Rcmd UDF, I have it installing, executing, and uninstalling:
code:
 	$dl="q"
$svrpath="\\server\shared"
$tools="\\server\logon\tools"
use "\\$name\ipc$$"
$targetSystemRoot = readvalue("\\$name\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\","SystemRoot")
shell '%comspec% /c $tools\xnet list $target | find /i "rcmdsvc" > nul'
if @error = 0
shell '%comspec% /c $tools\xnet stop \\$name\rcmdsvc > nul'
shell '%comspec% /c $tools\xnet remove \\$name\rcmdsvc /y > nul'
endif
copy "$tools\rcmd*.exe" "\\$name\admin$$\system32"
if @error <> 0 exit(@error) endif
shell '%comspec% /c $tools\xnet install \\$name\rcmdsvc /b:$targetsystemroot\system32\rcmdsvc.exe /n:"Remote Command Service" /u:localsystem /i:y /s:auto > nul'
shell '%comspec% /c $tools\xnet start \\$name\rcmdsvc > nul'
shell '%comspec% /c $tools\rcmd.exe \\$name net use $dl: $svrpath'
shell '%comspec% /c $tools\xnet stop \\$name\rcmdsvc > nul'
shell '%comspec% /c $tools\xnet remove \\$name\rcmdsvc /y > nul'
del "$destdir\rcmdsvc.exe"
use "$target\ipc$$" /delete

However, the system account cannot access the network.

I have tried to use SOON.EXE to schedule a Job
code:
 C:\>soon \\client 61 /interactive "cmd /c net use q: \\server\shared" 

With the same result.

Any Ideas...


LonkeroAdministrator
(KiX Master Guru)
2002-12-05 04:34 PM
Re: remotely create mapped drive

and at does not work?

Sealeopard
(KiX Master)
2002-12-05 04:35 PM
Re: remotely create mapped drive

You will need to use the Task Scheduler since it gives you the option to define a useraccount. Alternatively the Scheduler Service must be started under a local user account and not the SYSTEM account in order to gain network connectivity

Radimus
(KiX Supporter)
2002-12-05 04:36 PM
Re: remotely create mapped drive

it functions... But the security context cannot access the network.

BTW, Soon is a reskit wrapper for AT. Just to make 'quickie' tasks


Radimus
(KiX Supporter)
2002-12-05 04:49 PM
Re: remotely create mapped drive

if I specify a user account, will it act upon the user's desktop

Radimus
(KiX Supporter)
2002-12-05 04:54 PM
Re: remotely create mapped drive

http://support.microsoft.com/default.aspx?scid=kb;en-us;158273

http://support.microsoft.com/default.aspx?scid=kb;en-us;158825

[ 05. December 2002, 17:06: Message edited by: Radimus ]


JochenAdministrator
(KiX Supporter)
2002-12-05 08:51 PM
Re: remotely create mapped drive

Ey Rad,

you know that you can specify an Account to run rcmd with ?

Hmmm ... maybe this won't work neither


Radimus
(KiX Supporter)
2002-12-05 09:04 PM
Re: remotely create mapped drive

This is turning out to be harder than I thought.

The basic idea is to be able to map a drive for a user without having to remote control it... but it is looking like this isn't gonna happen.


Sealeopard
(KiX Master)
2002-12-05 09:07 PM
Re: remotely create mapped drive

It's definitely doable, however, the script must be execute under the user's account. Can't you just copy a link to his desktop and have him click it?

LonkeroAdministrator
(KiX Master Guru)
2002-12-05 09:52 PM
Re: remotely create mapped drive

eh?
doesn't the at service use current users rights when running in interactive mode?


Radimus
(KiX Supporter)
2002-12-06 03:13 PM
Re: remotely create mapped drive

I think that either a desktop batch file or a regwrite to the runonce key is about the best that can be done.

anything too complex is more trouble than it worth... remote control would just be easier.


Sealeopard
(KiX Master)
2002-12-06 03:55 PM
Re: remotely create mapped drive

Got a solution. And it's even very straight-forward and can be done with remote registry edit, too!
code:
[HKEY_CURRENT_USER\Network\O]
"RemotePath"="\\\\server\\share"
"UserName"=""
"ProviderName"="Microsoft Windows Network"
"ProviderType"=dword:00020000
"ConnectionType"=dword:00000001

I exported a example mapping from HKEY_CURRENT_USER, changed the drive letter in the registry key, used a different RemotePath, and reimported the .REG file back into the registry. After hitting 'Refresh' in the Explroer, i had the additional drive.

Give it a try, you should be able to write to \\COMPUTER\HKEY_CURRENT_USER, too.


Les
(KiX Master)
2002-12-06 04:02 PM
Re: remotely create mapped drive

Actually Jens, HKCU is not available remotely. You would have to go through HKEY_USERS\SID.

Sealeopard
(KiX Master)
2002-12-06 04:04 PM
Re: remotely create mapped drive

Yes, that is true. I even do this in my own scripts whne writing to the registry. Should have been more precise with regards to the remote registry write.

Radimus
(KiX Supporter)
2002-12-06 04:06 PM
Re: remotely create mapped drive

that's OK.. I knew that.

but since it isn't CU, the user may not get it until logon


Sealeopard
(KiX Master)
2002-12-06 04:08 PM
Re: remotely create mapped drive

[Confused]
I thought you want to remotely map a drive for a user that is already logged onto the computer?


Radimus
(KiX Supporter)
2002-12-06 04:10 PM
Re: remotely create mapped drive

I do... but doesn't NT read user@sid at logon and place into hkcu. and logoff writes back to @sid

writing to @sid when the user is logged on, may not affect the current environment


Sealeopard
(KiX Master)
2002-12-06 04:13 PM
Re: remotely create mapped drive

I thought it's just a dynamic copy of HKEY_USERS\@SID and thus any change to that part will automatically affect the HKEY_CURRENT_USER setting.

Okay, I just tested this. I've made an registry entry in HKEY_USERS\@SID and then looked at HKEY_CURRENT_USER, and ..., the registry key was there!

[ 06. December 2002, 16:19: Message edited by: sealeopard ]


Radimus
(KiX Supporter)
2002-12-06 04:17 PM
Re: remotely create mapped drive

cool beans...

I have some reusable code to get the @sid of remote user.

cool


Les
(KiX Master)
2002-12-06 04:42 PM
Re: remotely create mapped drive

Well, if the user is not logged on then the hive would not be loaded... but then, the mapping could be put in their logon script anyway.

You could try GetSID(), my one and only contribution to the UDF lib.


Radimus
(KiX Supporter)
2002-12-06 05:49 PM
Re: remotely create mapped drive

this makes a static mapping, I'll make a quickie popup to get the parameters later...

code:
Function MapDrive
$index=0
:sidloop
$sid=enumkey("\\$name\hkey_users\",$index)
if not @error and not instr($sids,"_")
$HKUsidSMWCVE = "HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion\Explorer"
$LogonName=readvalue("\\$name\$HKUsidSMWCVE","Logon User Name")
if not $remoteuser="@domain\$LogonName"
$index=$index+1
$sid=''
goto sidloop
endif
endif
if $sid
$letter="q"
$newpath="\\wheelerc\shared"
$=writevalue("\\$name\HKEY_USERS\$sid\Network\$letter","RemotePath","$newpath",REG_SZ)
$=writevalue("\\$name\HKEY_USERS\$sid\Network\$letter","UserName","",REG_SZ)
$=writevalue("\\$name\HKEY_USERS\$sid\Network\$letter","ProviderName","Microsoft Windows Network",REG_SZ)
$=writevalue("\\$name\HKEY_USERS\$sid\Network\$letter","ProviderType","131072",REG_Dword)
$=writevalue("\\$name\HKEY_USERS\$sid\Network\$letter","ConnectionType","00000001",REG_Dword)
endif
GetDrives()
endfunction

now, I'll write the inverse of this to delete a mapping...

[ 06. December 2002, 17:50: Message edited by: Radimus ]


Sealeopard
(KiX Master)
2002-12-06 05:51 PM
Re: remotely create mapped drive

Just do a DELTREE for the drive letter that you want to delete.

Radimus
(KiX Supporter)
2002-12-06 07:23 PM
Re: remotely create mapped drive

thanks [Razz] [Roll Eyes]

However, I will also need to check for persistence.

[ 06. December 2002, 19:24: Message edited by: Radimus ]


Radimus
(KiX Supporter)
2002-12-06 08:22 PM
Re: remotely create mapped drive

this is the function to get the sid of a remote user (assuming the user is logged in)
code:
 Function RemoteSid($computer, $remoteusername)
dim $sid, $logonname, $index, $HKUsidSMWCVE
$index=0
:sidloop
$sid=enumkey("\\$computer\hkey_users\",$index)
if not @error and not instr($sid,"_")
$HKUsidSMWCVE = "HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion\Explorer"
$LogonName=readvalue("\\$computer\$HKUsidSMWCVE","Logon User Name")
if $remoteusername=$LogonName
$RemoteSid=$sid
exit 0
return
else
$index=$index+1
$sid=''
exit 1
goto sidloop
endif
endif
endfunction