Sign in to follow this  
Followers 0
byoda

Creating Remote Share

14 posts in this topic

I am trying to create a Remote Share, but get an error message with the following code "Variable must be of type "Object". Any suggestions or other way to create remote share without wmi? Thanks.

Const $FILE_SHARE = 0

Const $MAXIMUM_CONNECTIONS = 5

$strComputer = "test-pt"

$objWMIService = ObjGet("winmgmts:\\"&$strComputer&"\root\CIMV2")

$objNewShare = $objWMIService.Get("Win32_Share")

$errReturn = $objNewShare.Create("c:\", "PublicShare", $FILE_SHARE, $MAXIMUM_CONNECTIONS, "Public")

Share this post


Link to post
Share on other sites



Add a COM Error Handler to get details. See help file under OBJ/COM reference for an example.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Add a COM Error Handler to get details. See help file under OBJ/COM reference for an example.

:mellow:

Thank you. I get an access denied. I guess I need to set credentials. Any suggestions? Ive looked at other scripts and posts, but nothing. Thanks again.

Share this post


Link to post
Share on other sites

Thank you. I get an access denied. I guess I need to set credentials. Any suggestions? Ive looked at other scripts and posts, but nothing. Thanks again.

Here is the script

Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling.

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler

Const $FILE_SHARE = 0

Const $MAXIMUM_CONNECTIONS = 25

$objWMIService = ObjGet("winmgmts:\\systemname\root\CIMV2")

$Locator=ObjCreate("WbemScripting.SWbemLocator")

$Connection=$Locator.ConnectServer("systemname", "root\cimv2", "Administrator", "password")

$objNewShare = $objWMIService.Get("Win32_Share")

$errReturn = $objNewShare.Create("c:\", "PublicShare", $FILE_SHARE, $MAXIMUM_CONNECTIONS, "Public share")

if $g_eventerror then Msgbox(0,"","the previous line got an error.")

Exit

; This is my custom error handler

Func MyErrFunc()

$HexNumber=hex($oMyError.number,8)

Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _

"Number is: " & $HexNumber & @CRLF & _

"Windescription is: " & $oMyError.windescription )

$g_eventerror = 1 ; something to check for when this function returns

Endfunc

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You may just need some security settings in your ObjGet():

$objWMIService = ObjGet("winmgmts:{ImpersonationLevel=Impersonate, AuthenticationLevel=PktPrivacy}!\\" & $strComputer & "\root\CIMV2")

:mellow:

P.S. You didn't say where you got the ACCESS DENIED.

And you seem to be using both WMI moniker and SwebmService methods to connect to the same space, "root\cimv2". But $Locator and $Connection are not used after being initialized, so why is it there at all?

:P

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You may just need some security settings in your ObjGet():

$objWMIService = ObjGet("winmgmts:{ImpersonationLevel=Impersonate, AuthenticationLevel=PktPrivacy}!\\" & $strComputer & "\root\CIMV2")

:mellow:

P.S. You didn't say where you got the ACCESS DENIED.

And you seem to be using both WMI moniker and SwebmService methods to connect to the same space, "root\cimv2". But $Locator and $Connection are not used after being initialized, so why is it there at all?

:P

1. I tried with the security setting you sent and I am still getting the following error message with the COM Error Handler you told me to use. "We intercepted a COM Error. Number is 800070005. Windescription is: Access is denied."

2. I tried with $strComputer="localhost" and it worked. It is not working with $strComputer as a remote IP or remote hostname, which i set in the host file. This is the main problem. I cannot get it to connnect remotely.

3. You were correct on the $locator and $connection. It has been taken out of the equation.

Share this post


Link to post
Share on other sites

And you're sure the account running this has correct perms on the remote target?

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I am using Administrator/Password. Does something need to be done on the remote system to allow access? Is that what you are saying?

Share this post


Link to post
Share on other sites

No, you applied username/password to the SwebmLocator connection.

The credentials applied to the ObjGet() method are those running the local script. Is this a domain for example, where the domain admin account running the script also has admin perms on the remote target?

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I am using Administrator/Password. Does something need to be done on the remote system to allow access? Is that what you are saying?

This is not a domain. This is a client/server setup on a workgroup. I want the client to create a share on the server.

Share this post


Link to post
Share on other sites

This is not a domain. This is a client/server setup on a workgroup. I want the client to create a share on the server.

Also,

This is where I am getting my source from.

http://blogs.technet.com/b/heyscriptingguy/archive/2005/01/07/how-can-i-share-a-folder-on-a-remote-computer.aspx

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Being an admin on the client doesn't automatically give you any perms on the server. So how did you get permissions on the remote machine?

:mellow:

Edit:

Also,

This is where I am getting my source from.

http://blogs.technet.com/b/heyscriptingguy/archive/2005/01/07/how-can-i-share-a-folder-on-a-remote-computer.aspx

That article assumes the VBScript is being run in a context with required permissions on the remote computer. Did you try doing this in VBScript? If you don't have the permissions, it won't work any better in VBScript than it does in AutoIt.

:P

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Being an admin on the client doesn't automatically give you any perms on the server. So how did you get permissions on the remote machine?

:mellow:

Edit:

That article assumes the VBScript is being run in a context with required permissions on the remote computer. Did you try doing this in VBScript? If you don't have the permissions, it won't work any better in VBScript than it does in AutoIt.

:P

1. THANK YOU FOR YOUR HELP :party:

2. I have attached the working script. It was about setting the user/pass.

3. Let me know if I can help boost your rating......

Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling.

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler

$strComputer = "systemname"

$strUser = "user"

$strPassword = "pass"

$FILE_SHARE=0

$MAXIMUM_CONNECTIONS=25

$Locator=ObjCreate("WbemScripting.SWbemLocator")

$objWMIService = $Locator.ConnectServer($strComputer, "\root\CIMV2", $strUser, $strPassword)

$objNewShare = $objWMIService.Get("Win32_Share")

;Connection=$Locator.ConnectServer($strComputer, "root\cimv2")

$errReturn = $objNewShare.Create("g:\test", "PublicShare", $FILE_SHARE, $MAXIMUM_CONNECTIONS, "Public")

if $g_eventerror then Msgbox(0,"","the previous line got an error.")

Exit

; This is my custom error handler

Func MyErrFunc()

$HexNumber=hex($oMyError.number,8)

Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _

"Number is: " & $HexNumber & @CRLF & _

"Windescription is: " & $oMyError.windescription )

$g_eventerror = 1 ; something to check for when this function returns

Endfunc

Share this post


Link to post
Share on other sites

Using the SwebmLocator all the way through makes good sense. Glad you got it working.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
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
Sign in to follow this  
Followers 0