Jump to content
Sign in to follow this  
ryunik

InputBox is black when executed with PsExec

Recommended Posts

ryunik

Hi All

I am working on a script that will map a network share remotely. Since network shares are mapped under user context it will require the credentials of the user.

To avoid asking the user for these explicitly, I wrote a script that will prompt them for their Username and Password through InputBox (See Below.)

To keep the password as secret as possible I generate a random string and use _StringEncrypt() passing all info through an .ini file.

The script uses PsExec on the local machine to execute the InputBox script on the remote machine.

However, when the script is executed the prompts show up black. Information can still be typed in the boxes but you can't see anything. (See attachment)

I've searched through the forum a few times and found a couple of posts with similar problems but they were resolved using PsExec...since I am already doing that I am not sure where to go from here.

Any thoughts would be appreciated and any advice on better code is more than welcome.

Main code that will transfer the InputBox and execute the needed commands:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=test\netdrive.exe
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <String.au3>
$hname = InputBox("Hostname/Ip", "Please enter the Hostname or IP for the Machine: ")
FileCopy("C:\netdrive_user.exe", "\\" & $hname & "\C$\")
$pwd = ""
Dim $aSpace[3]
$digits = 15
For $i = 1 To $digits
$aSpace[0] = Chr(Random(65, 90, 1)) ;A-Z
$aSpace[1] = Chr(Random(97, 122, 1)) ;a-z
$aSpace[2] = Chr(Random(48, 57, 1)) ;0-9
$pwd &= $aSpace[Random(0, 2, 1)]
Next
IniWrite("\\" & $hname & "\C$\netdrive.ini", "ePsswd", "ePass", $pwd)
RunWait("C:\Windows\Support\PSExec.exe \\" & $hname & Chr(32) & "-i" & Chr(32) & "C:\netdrive_user.exe")
;RunWait("\\" & $hname & "\C$\netdrive_user.exe", "\\" & $hname & "\C$\")
$pwssd = _StringEncrypt(0, IniRead("\\" & $hname & "\C$\netdrive.ini", "Password", "Password", "Not Found"), $pwd, 1)
$uname = IniRead("\\" & $hname & "\C$\netdrive.ini", "Username", "UName", "Not Found")

Code for the InputBox:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=..\..\..\..\..\netdrive_user.exe
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Misc.au3>
#include <String.au3>
$uname = InputBox("UserName", "Please Enter your Username: ")
$psswd = InputBox("Password", "Please Enter your Password: ", "", "*")
$ePsswd = _StringEncrypt(1, $psswd, IniRead("C:\netdrive.ini", "ePsswd", "ePass", ""))
IniWrite("C:\netdrive.ini", "Username", "UName", $uname)
IniWrite("C:\netdrive.ini", "Password", "Password", $ePsswd)

post-76486-0-38712700-1359052339_thumb.p

Share this post


Link to post
Share on other sites
JLogan3o13

Hi, ryunik, welcome to the forum. Is there any reason the drive mapping has to be done remotely? Could you not just create the script using DriveMapAdd, and then place the script in the Users' startup folders? Then it will automatically run in the User context, and you won't have to worry about credentials at all. You can always use PSExec to update the script on the remote machines if drive mappings need to change, but the actual processing is handled locally.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
ryunik

The short answer is no. I could use DriveMapAdd. However, by request of the team that I am writing this for they don't want the tool to be passed around to different buildings without it going through them first.

Thanks for the quick reply!

Share this post


Link to post
Share on other sites
LarryDalooza

Running PSExec on the command line correctly for interactive? Look into OWExec... it launches in target machine current user context.

Lar


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites
BrewManNH

Have you tried it with a small GUI and and Input control instead of using an InputBox?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
ryunik

This is the command I use for the PsExec: RunWait("C:WindowsSupportPSExec.exe " & $hname & Chr(32) & "-i" & Chr(32) & "C:netdrive_user.exe") So I am thinking that should be correct.

I will definitely look into OWExec though.

Brew:

I have just recently thought about using a small GUI instead of InputBox. I will start working with that and see what I come up with.

Share this post


Link to post
Share on other sites
ryunik

Lar: OwExec worked like Magic!

Brew: I went ahead and created the GUI but was still running into the same problem. Using OWExec though worked.

Thanks everyone!

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  

×