Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: wntAddPrinter after WntRunAsUser
What I am trying to do is to create a winbatch script that will share the users client printer on the Windows Terminal box and then do a wntAddPrinter to setup LPT1 to print to it.
Since a normal user does not have rights to share a printer under NT, I am doing a wntRunAsUser to run the script in the context of an account that does have rights to create a share.
usrid="Admin" pswd="mypasswrd" rslt=wNTRunAsUser("",usrid,pswd,3,0) rslt=wntShareAdd("", pname, pshr, 1, -1)
The problem lies after this, when I am trying to do the wntAddprinter
port=StrCat("\\",srv,"\",pshr) rslt=wNTAddPrinter(@Default,@Default,port,"lpt1", 0)
It returns a result code of 1, but when I do a NET USE command, nothing is connected.
If I run my script as an Admin, it runs fine, because the wntrunasuser command errors out because the Admin account doesn't have the proper rights to do a runasuser command..
It seems to be acting like when you use the AT command to run a batch file that does a NET USE to a network drive. The drive shows up in Explorer, but it says "not connected".
I am using a code of 3 in the runasuser command which says Run Interactively, but it seems like the wntAddPrinter is not setting up the LPT port for the current users session.
Any ideas???
You can specify a user name of "" to end the impersonation. After the wntshareadd, then attempt to execute wntAddPrinter....
Something like...
usrid="Admin" pswd="mypasswrd" rslt=wNTRunAsUser("",usrid,pswd,3,0) rslt=wntShareAdd("", pname, pshr, 1, -1) ;remove impersonation rslt=wNTRunAsUser("","","",0,0) port=StrCat("\\",srv,"\",pshr) rslt=wNTAddPrinter(@Default,@Default,port,"lpt1", 0)
See if that helps. Let us know if this solves your problem....
Thanks for following up for me.
That is exactly what it needed. Works great now!
Article ID: W14475
Filename: wntAddPrinter after WntRunAsUser.txt
File Created: 2000:05:02:10:17:38
Last Updated: 2000:05:02:10:17:38