Jump to content
Sign in to follow this  
BrettF

Creating an Network Share

Recommended Posts

BrettF

I did find this code in a topic, but I get the error that:

Variable must be of type "Object".:

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

$objNewShare = $objWMIService^ ERROR

Const $FILE_SHARE = 0
Const $MAXIMUM_CONNECTIONS = 25
$strComputer = "atl-ws-01"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$objNewShare = $objWMIService.Get("Win32_Share")
$errReturn = $objNewShare.Create(@ScriptDir & "\WebKiosk", "WebKiosk", 0, 25, "Exod-Kiosk Codes/Times")

Thanks

Share this post


Link to post
Share on other sites
Uten

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
if @error then 
  Msgbox (0,"ERROR","Error: Probably Can't create object")
  exit
endif

Just a thought.

Share this post


Link to post
Share on other sites
BrettF

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
if @error then 
  Msgbox (0,"ERROR","Error: Probably Can't create object")
  exit
endif

Just a thought.

Ok.... Thanks. How can I fix it?

The thread I used was this one.

Share this post


Link to post
Share on other sites
ptrex

@all

this will create a network share.

$strComputer = "."
$strPath = "c:\AutoIT"
$strName = "Scripts"
$intType = 0 ; share a disk drive resource
$intMaxAllowed = 10 
$strDescr = "AU Scripts"

$objWMI = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
 $objShare = $objWMI.Get("Win32_Share")
$intRC = $objShare.Create($strPath, $strName, $intType, $intMaxAllowed, $strDescr)

if $intRC <> 0 then
 ConsoleWrite ("Error creating share: " & $intRC)
else
 ConsoleWrite ("Successfully created share")
EndIf

Enjoy !!

ptrex

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  

×