while ( system("net use $drive /DELETE") ) { : (I can provide the details if necessary) } #### use Win32::NetResource qw(:DEFAULT GetSharedResources GetError AddConnection CancelConnection); my $Domain = 'aaaaaaaa'; my $Account = 'bbbbbbbb'; my $Password = 'cccccccc'; my $Server = 'dddddddd'; my $LocalDrive = 'X:'; my $UserName = '${Domain}\\${Account}'; my $Connection = 0; my $ShareInfo = { 'path' => "C:\\temp", 'netname' => "MyShare", 'remark' => "It is good to share", 'passwd' => "", 'current-users'=> 0, 'permissions' => 0, 'maxusers' => -1, 'type' => 0, }; my %NETRESOURCE = ( 'Scope' => 'RESOURCE_REMEMBERED', 'Type' => 'RESOURCETYPE_DISK', 'DisplayType' => 'RESOURCEDISPLAYTYPE_SHARE', 'Usage' => 'RESOURCEUSAGE_CONTAINER', 'LocalName' => "$LocalDrive", 'RemoteName' => "\\\\$Server\\D\$", 'Provider' => "$Server" ); AddConnection(\%NETRESOURCE,$Password,$UserName,$Connection); # CancelConnection($Name,$Connection,$Force);