Solved

vb script: sendkeys not working

Posted on 2006-11-01
10
1,693 Views
Last Modified: 2008-02-07
I have an application that I have started working on to create an environmental variable using the "runas" command.  The application is firing and no errors are found, but I am prompted for the password and the sendkeys command isn't working.  The window will stay open until I close it from frustration.  Here is the program:

'Set oFSO = CreateObject("Scripting.FileSystemObject")
set oShell= Wscript.CreateObject("WScript.Shell")
password = "{[}password{)}"                                                                          'the special characters are by design

intButton = oShell.Popup("Conducting an EAB update.  Do not interrupt this process.  Do not open any applications.  You will be logged out when completed.",5,"EAB Update",48)
program = "\\Eabrn1\cadd\Bentley\updates\supporting_files\inroads_server_licensing.reg"
licvalue= "\\Eabrn1\cadd\Bentley\Civil\licensing\"


      '---------------------------------------------------      
      'Replace the path with the program you wish to run within the quotes...
      '---------------------------------------------------
      oShell.Run "runas /user:asetdm\adeashwy \\Eabrn1\cadd\Bentley\updates\supporting_files\inroads_server_licensing.reg"
      WScript.Sleep 100
      oShell.AppActivate "runas.exe"
      '---------------------------------------------------
      'enter the admin password to be used.
      'within the quotes.  the curly brackets are needed
      'to send special characters.  You must include the tilde "~"
      'The tilde is the equivalent of hitting enter on the keyboard
      '---------------------------------------------------
      oShell.SendKeys password
      oShell.SendKeys "{ENTER}"                                                                           'this is questionable

'Wscript.Quit



0
Comment
Question by:prostang
  • 5
  • 4
10 Comments
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 17854433
Does RunAs open as a window or a console application, because on my XP computer its opening as a console and the title is "C:\Windows\System32\runas.exe"


Brian
0
 

Author Comment

by:prostang
ID: 17854496
you are right.  I just put that line of code in shortly before posting here.  The app is run when the user logs on so the focus is on the console.
0
 
LVL 6

Expert Comment

by:dave_moats
ID: 17857938
Looks like if you specify set a variable to store the result from the oShell.Run call and then use it in the oShell.AppActivate, it will send the keys to the window.  Atleast it did on my XP box :-)

Since I do not know what you are actually doing, I spawned an application using runas.  

     ---------------------------------------------------
     'Replace the path with the program you wish to run within the quotes...
     '---------------------------------------------------
     cmdID = oShell.Run( "runas /user:asetdm\adeashwy \\Eabrn1\cadd\Bentley\updates\supporting_files\inroads_server_licensing.reg" )
     WScript.Sleep 100
     oShell.AppActivate( cmdID )
     '---------------------------------------------------
     'enter the admin password to be used.
     'within the quotes.  the curly brackets are needed
     'to send special characters.  You must include the tilde "~"
     'The tilde is the equivalent of hitting enter on the keyboard
     '---------------------------------------------------
     oShell.SendKeys password
     oShell.SendKeys "~"   'Tried both "~" and "{ENTER}" and both worked

Dave
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:prostang
ID: 17859363
The .reg file being executed changes an environmental variable for an application to acquire a shared site license.  I have to go thru this method because the users aren't admin.  I copied and pasted your cmdID line and changed the AppActivate line and it still doesn't send the password.
0
 
LVL 6

Expert Comment

by:dave_moats
ID: 17859430
Are these machines XP ?

Is the .reg file a registry file and you are trying to update the registry?  Or is it just a similiar name?
0
 

Author Comment

by:prostang
ID: 17859620
here is the what the .reg file has:  

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
-"INROADS_LICENSING"="\\\\Asgopinon\\cadd\\Program Files\\Bentley\\Civil\\licensing"

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]
"INROADS_LICENSING"="\\\\Eabrn1\\CADD\\Bentley\\Civil\\licensing\\"

The value has changed servers, so this is the file that will do it for me.  When I run the file thru the Window Run command, it will work if I don't use the runas statement.  I will not work (delete or create the new registry value) if I use the runas command.
0
 

Author Comment

by:prostang
ID: 17859714
I am getting a "...reg is not a valid Win32 application." error when trying to run the .reg file from the cmd window using the runas command.

Sorry, it is an XP pro machine with SP2.
0
 
LVL 6

Expert Comment

by:dave_moats
ID: 17859728
Yes I see that....I think it is  something with passing the command to runas incorrectly
0
 
LVL 6

Accepted Solution

by:
dave_moats earned 500 total points
ID: 17859804
Try this, I create a variable to hold the command, this will install a test .reg file on my box.

cmdText = "runas /user:asetdm\adeashwy ""regedit /s \\Eabrn1\cadd\Bentley\updates\supporting_files\inroads_server_licensing.reg"""

     '---------------------------------------------------
     'Replace the path with the program you wish to run within the quotes...
     '---------------------------------------------------
     cmdID = oShell.Run( cmdText )
     WScript.Sleep 100
     oShell.AppActivate( cmdID )
     '---------------------------------------------------
     'enter the admin password to be used.
     'within the quotes.  the curly brackets are needed
     'to send special characters.  You must include the tilde "~"
     'The tilde is the equivalent of hitting enter on the keyboard
     '---------------------------------------------------
     oShell.SendKeys password
     oShell.SendKeys "~"   'this is questionable
0
 

Author Comment

by:prostang
ID: 17860554
OK.  I tried your code on a different network and different computer and voila, it worked.  I then tried my original code, and it also worked.  Thanks for your efforts.  I know that the computer I need it to work on has issues, and after talking to the local IT guys, it seems to be part of a degrading network (there are many other symptoms).  Thanks again.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now