byoda Posted June 14, 2010 Share Posted June 14, 2010 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") Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 14, 2010 Share Posted June 14, 2010 Add a COM Error Handler to get details. See help file under OBJ/COM reference for an example. 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 Link to comment Share on other sites More sharing options...
byoda Posted June 15, 2010 Author Share Posted June 15, 2010 Add a COM Error Handler to get details. See help file under OBJ/COM reference for an example.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. Link to comment Share on other sites More sharing options...
byoda Posted June 15, 2010 Author Share Posted June 15, 2010 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 scriptGlobal $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 handlerConst $FILE_SHARE = 0Const $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 Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 15, 2010 Share Posted June 15, 2010 (edited) You may just need some security settings in your ObjGet(): $objWMIService = ObjGet("winmgmts:{ImpersonationLevel=Impersonate, AuthenticationLevel=PktPrivacy}!\\" & $strComputer & "\root\CIMV2") 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? Edited June 15, 2010 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 Link to comment Share on other sites More sharing options...
byoda Posted June 15, 2010 Author Share Posted June 15, 2010 You may just need some security settings in your ObjGet(): $objWMIService = ObjGet("winmgmts:{ImpersonationLevel=Impersonate, AuthenticationLevel=PktPrivacy}!\\" & $strComputer & "\root\CIMV2") 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? 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. Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 15, 2010 Share Posted June 15, 2010 And you're sure the account running this has correct perms on the remote target? 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 Link to comment Share on other sites More sharing options...
byoda Posted June 15, 2010 Author Share Posted June 15, 2010 I am using Administrator/Password. Does something need to be done on the remote system to allow access? Is that what you are saying? Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 15, 2010 Share Posted June 15, 2010 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? 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 Link to comment Share on other sites More sharing options...
byoda Posted June 15, 2010 Author Share Posted June 15, 2010 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. Link to comment Share on other sites More sharing options...
byoda Posted June 15, 2010 Author Share Posted June 15, 2010 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 Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 15, 2010 Share Posted June 15, 2010 (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? 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.aspxThat 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. Edited June 15, 2010 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 Link to comment Share on other sites More sharing options...
byoda Posted June 15, 2010 Author Share Posted June 15, 2010 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? 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.1. THANK YOU FOR YOUR HELP 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 Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 15, 2010 Share Posted June 15, 2010 Using the SwebmLocator all the way through makes good sense. Glad you got it working. 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 Link to comment Share on other sites More sharing options...
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