Solved

vb script: sendkeys not working

Posted on 2006-11-01
10
1,694 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

860 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