I've had problems using the system call to pass the "net use" command. I can't get it to work just using "net use \\\\$computer ..." and I've had no success using system("net use \\\\$computer\\ipc\$...."
No matter how I delimit the IPC$ parameter, it ignores the $. Very frustrating. I eventually came up with the use Win32::Lanman module used in the following manner (this example gets the OS Version from the registry):
use Win32::TieRegistry(Delimiter => "/", ArrayValues => 0);
use Win32::Lanman;
$host = "10.10.10.10";
$pass = "yourpass";
$user = "youradmin";
$domain = "yourdomain";
if(!Win32::Lanman::NetUseAdd({remote => "\\\\$host\\ipc\$",
password => "$pass",
username => "$user",
domain => "$domain",
asg_type => &USE_IPC}))
{
print "connect: Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
$remoteKey = $Registry->{
"//$host/LMachine/SOFTWARE/Microsoft/Windows NT/Curre
+ntVersion/ProductName"} or die "Can't read from $host. Error: $^E\n";
print "$remoteKey\n";
if(!Win32::Lanman::NetUseDel("\\\\$host\\ipc\$"))
{
print "disconnect: Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Hope this helps. If anyone has a more elegant solution, I'd love to hear about it!