?
Solved

VBScript/HTA Help! run command line on click

Posted on 2009-04-15
9
Medium Priority
?
5,100 Views
Last Modified: 2012-06-22
Hello,

I'm trying to make an hta that will unlock a users account using joeware's unlock tool. It's an EXE that you run in cmd and give it an attribute. "Unlock.exe unlock . username"

I have been able to get it to open a command window, but now put in the unlock.exe unlock . username with the following code

Sub cmdSubmit
    Const NORMAL_WINDOW = 1
    Set objShell = CreateObject("Shell.Application")
    objShell.ShellExecute "cmd.exe", "%userprofile%\appdata\local\microsoft\windows sidebar\gadgets\teepe.gadget\EXE\Unlock.exe unlock . name", , , NORMAL_WINDOW
End Sub

Any help would be greatly appreciated. Below is my whole code.


<html>
 
<head>
   <title>Woot</title>
 
    <style>
        body
        {
            width: 129;
            height: 203;
            padding: 0;
            margin: 0;
            background-image: url(../IMG/background.png);
            background-repeat: no-repeat;
        }
    .style1 {
	color: #FFFFFF;
	font-family: Calibri;
	font-weight: bold;
	font-size: 11px;
}
    .style2 {
	color: #FFFFFF;
	font-family: Calibri;
	font-weight: bold;
	font-size: 14px;
}
    .style3 {
	color: #FFFFFF;
	font-family: Calibri;
	font-weight: bold;
	font-size: 5px;
}
    </style>
</head>
<body>
<table width='116' border='0' cellspacing='0' cellpadding='0' style='padding-left:10px'>
<tr>
<td>
<div align='center' class='style2'>
  <p><b> Locked Accounts</b></p>
</div></td>
</tr>
<tr>
<td>
<span class="style3"><br></span>
<span class='style1'>
 
 
<script Language="VBScript">
Sub cmdSubmit
    Const NORMAL_WINDOW = 1
    Set objShell = CreateObject("Shell.Application")
    objShell.ShellExecute "cmd.exe", "%userprofile%\appdata\local\microsoft\windows sidebar\gadgets\teepe.gadget\EXE\Unlock.exe unlock . document.test.name.value", , , NORMAL_WINDOW
End Sub
 
	   On Error Resume Next 
 
	   Const ADS_SCOPE_SUBTREE = 2 
 
	   Set objConnection = CreateObject("ADODB.Connection") 
	   Set objCommand =   CreateObject("ADODB.Command") 
 
	   objConnection.Provider = "ADsDSOObject" 
	   objConnection.Open "Active Directory Provider" 
 
	   Set objCommand.ActiveConnection = objConnection 
 
	   objCommand.Properties("Page Size") = 1000 
	   objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
	   objCommand.CommandText = _ 
	      "SELECT distinguishedName FROM 'LDAP://dc=,dc=,dc=,dc=com' WHERE objectCategory='user'" 
 
	   Set objRecordSet = objCommand.Execute 
	   objRecordSet.MoveFirst 
 
	   Do Until objRecordSet.EOF 
	   strDN = objRecordset.Fields("distinguishedName").Value 
	   Set objUser = GetObject ("LDAP://" & strDN) 
	   strislocked = objuser.isAccountlocked 
	   straccount = objuser.displayName
	   straccount2 = objuser.samAccountName
  	     If strislocked = True Then 
            document.write "<FORM style='margin: 0;' name='test'><input style='margin: 0;' name='name' type='hidden' id='name' value='"+straccount2+"'>"+ straccount +" <a style='margin: 0;' href='#' onclick='cmdSubmit()'>Out</a></form>"
			objRecordSet.MoveNext
 	     Else 
	        objrecordset.MoveNext 
		End If
	   Set objuser = Nothing 
	   Loop 
</script>
</span>
</td>
</tr>
</table>
</body>
</html>

Open in new window

0
Comment
Question by:teepes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
9 Comments
 
LVL 7

Expert Comment

by:sj_hicks
ID: 24153662
A couple options:
1)  Run unlock.exe directly, rather than using CMD.exe
2)  Use the /C (runs unlock then closes cmd): cmd /c unlock.exe....
3)  Use the /K (runs unlock then leaves cmd open): cmd /c unlock.exe....
4)  If this doesn't work, use WScript.Shell.Run:
oShell = CreateObject("WScript.Shell")
oShell.Run <command line>, 1, true

0
 

Author Comment

by:teepes
ID: 24157132
i figured it out. I just made a batch file that i point to, and carry the variable over using the %1.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 24163232
Hi, you could have also changed this:
    objShell.ShellExecute "cmd.exe", "%userprofile%\appdata\local\microsoft\windows sidebar\gadgets\teepe.gadget\EXE\Unlock.exe unlock . document.test.name.value", , , NORMAL_WINDOW

to this
    objShell.Run "cmd.exe /c ""%userprofile%\appdata\local\microsoft\windows sidebar\gadgets\teepe.gadget\EXE\Unlock.exe"" unlock " & document.test.name.value, 1, True

as long as document.test.name.value returned the username.

Regards,

Rob.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Comment

by:teepes
ID: 24167228
well i got everything working the only problem is that when i have it in my sidebar and click unlock, it unlocks the person but also opens another application window. Any idea on how to make it stop?
0
 

Author Comment

by:teepes
ID: 24167238
almost forgot here is the code

<html>
<head>
<hta:application
id="Locked Users"
applicationname="Locked Users"
border="dialog"
SCROLL="no"
caption="yes"
showintaskbar="yes"
singleinstance="yes"
sysmenu="yes"
>
   <title>Woot</title>
   <style>
        body
        {
            width: 129;
            height: 203;
            padding: 0;
            margin: 0;
            background-image: url(../IMG/background.png);
            background-repeat: no-repeat;
        }
    .style1 {
	color: #FFFFFF;
	font-family: Calibri;
	font-weight: bold;
	font-size: 11px;
}
    .style2 {
	color: #FFFFFF;
	font-family: Calibri;
	font-weight: bold;
	font-size: 14px;
}
    .style3 {
	color: #FFFFFF;
	font-family: Calibri;
	font-weight: bold;
	font-size: 5px;
}
    </style>
</head>
<script Language="VBScript">
Sub Window_OnLoad
		RefreshList
        iTimerID = window.setInterval("RefreshList", 10000)
    End Sub
 
Sub cmdSubmit(strtest)
        Set objShell = CreateObject("Wscript.Shell")
        objShell.Run """%userprofile%\appdata\local\microsoft\windows sidebar\gadgets\teepe.gadget\HTML\unlock.bat""" & strtest
End Sub
Sub RefreshList
	   On Error Resume Next 
 
 		ProcessList.InnerHTML = ""
 	
	   Const ADS_SCOPE_SUBTREE = 2 
 
	   Set objConnection = CreateObject("ADODB.Connection") 
	   Set objCommand =   CreateObject("ADODB.Command") 
 
	   objConnection.Provider = "ADsDSOObject" 
	   objConnection.Open "Active Directory Provider" 
 
	   Set objCommand.ActiveConnection = objConnection 
 
	   objCommand.Properties("Page Size") = 1000 
	   objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
	   objCommand.CommandText = _ 
	      "SELECT distinguishedName FROM 'LDAP://dc=,dc=,dc=,dc=com' WHERE objectCategory='user'" 
 
	   Set objRecordSet = objCommand.Execute 
	   objRecordSet.MoveFirst 
 
 		ProcessList.InnerHTML = "<FORM style='margin: 0;' name='test'>"
	   Do Until objRecordSet.EOF 
	   strDN = objRecordset.Fields("distinguishedName").Value 
	   Set objUser = GetObject ("LDAP://" & strDN) 
	   strislocked = objuser.isAccountlocked 
	   straccount = objuser.displayName
	   straccount2 = objuser.samAccountName
  	     If strislocked = True Then 
            ProcessList.InnerHTML = ProcessList.InnerHTML & straccount & " " & " <a style='color:#CCCCCC; margin: 0;' href='#' onclick='vbscript:cmdSubmit(""" & straccount2 & """)'>(Unlock)</a> <br>"
			objRecordSet.MoveNext
 	     Else 
	        objrecordset.MoveNext 
		End If
	   Set objuser = Nothing 
	   Loop
	   ProcessList.InnerHTML = ProcessList.InnerHTML
End Sub
 
</script>
 
<body>
<table width='116' border='0' cellspacing='0' cellpadding='0' style='padding-left:10px'>
<tr>
<td>
<div align='center' class='style2'>
  <p><b> Locked Accounts</b></p>
</div></td>
</tr>
<tr>
<td>
<span class="style3"><br></span>
<span class='style1'>
 
<span id = "ProcessList"></span>
 
</span>
</td>
</tr>
</table>
</body>
</html>

Open in new window

0
 

Author Comment

by:teepes
ID: 24167482
i got it. I had to take the href out of my onclick. But i have noticed that .hta is not the best thing for vista gadgets. It's a little buggy.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24172919
Good work.  They can be a bit buggy, particular with screen refreshes, but they get the job done...

Rob.
0
 

Author Comment

by:teepes
ID: 24173334
LOL i totally revamped it to use HTML,VBSCRIPT, JAVASCRIPT, and my EXE's.No .hta. Thanks for all your help it's running great now! Thanks
0
 

Author Closing Comment

by:teepes
ID: 31570432
Thanks i used your code :)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

752 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