1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
| <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="description" content="Created by Stuart Barrett">
<meta name="description" content="Last Update: 24/05/11">
<script language="VBScript">
intLeft = window.screenLeft
intTop = window.screenTop
window.moveTo -2000,-2000
window.ResizeTo 1,1
</script>
<title>PSExec Command Builder</title>
<HTA:APPLICATION
APPLICATIONNAME="PSExecCommandBuilder"
ID="objPSExecCommandBuilder"
VERSION="1.5"
BORDER="dialog"
APPLICATIONNAME="PSExecCommandBuilder"
SCROLL="no"
MAXIMIZEBUTTON="no"
SINGLEINSTANCE="yes"
CONTEXTMENU="no"
WINDOWSTATE="normal"/>
<style type="text/css">
body {
font-size: 0.9em;
cursor: default;
font-family: calibri, "Times New Roman", helvetica, sans-serif;
background-color: #eeeeee;
}
.hidden {
display: none;
visibility: hidden;
}
input {
font-family: verdana; "Times New Roman", calibri, helvetica, sans-serif;
}
input.button {
color: black;
cursor: hand;
background-color: white;
border: #000033 2px solid;
height: 25px;
}
input.text {
border: #000033 1px solid;
height: 23px;
padding-left: 3px;
}
input.btnhov {
border-color: #000033;
background-color: #cccccc;
}
input.disabled {
background-color: #eeeeee;
border-color: #888888;
cursor: default;
}
</style>
</head>
<script language="VBScript">
'#==============================================================================
'#==============================================================================
'# SCRIPT.........: PSExecCommandBuilder.hta
'# AUTHOR.........: Stuart Barrett
'# VERSION........: 1.5
'# CREATED........: 03/11/10
'# LICENSE........: Freeware
'# REQUIREMENTS...:
'#
'# DESCRIPTION....: Allows a user to build and perform PSExec commands
'# upon a machine using a form and also offers the unique
'# ability to save / open commands
'#
'# NOTES..........: Taken from my PC Management Utility, check it out:
'# http://community.spiceworks.com/scripts/show/585-computer-management-utility
'#
'# CUSTOMIZE......:
'#==============================================================================
'# REVISED BY.....:
'# EMAIL..........:
'# REVISION DATE..:
'# REVISION NOTES.:
'#
'#==============================================================================
'#==============================================================================
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
'#--------------------------------------------------------------------------
'# SUBROUTINE.....: RunPSExecCommands()
'# PURPOSE........: Allows a user to build and perform PSExec commands
'# upon a machine using a form and also offers the
'# ability to save / open commands
'# ARGUMENTS......:
'# EXAMPLE........:
'# NOTES..........:
'#--------------------------------------------------------------------------
Sub RunPSExecCommand()
On Error Resume Next
booPSExecInPath = False
If IsNull(txtComputerName.Value) OR txtComputerName.Value = "" OR txtComputerName.Value = "." Then
txtComputerName.Value = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
End If
txtComputerName.Value = UCase(txtComputerName.Value)
strPC = txtComputerName.Value
If NOT Reachable(strPC) Then
ShowDiv(NotFoundArea)
Exit Sub
End If
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strPC & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objItem In colComputer
strLoggedOn = objItem.UserName
If IsNull(strLoggedOn) Then strLoggedOn = "none"
Next
LoggedOnSpan.InnerHTML = Trim(strLoggedOn)
strPath = objShell.ExpandEnvironmentStrings("%path%")
arrPaths = Split(strPath, ";")
For i = 0 To UBound(arrPaths)
strPathFolder = arrPaths(i) & "\"
strPathFolder = Replace(strPathFolder, "\\", "\")
strPathFolder = Replace(LCase(strPathFolder), "%systemroot%", _
objShell.ExpandEnvironmentStrings("%systemroot%"))
If objFSO.FileExists(strPathFolder & "psexec.exe") Then
booPSExecInPath = True
strPSExecLocation = strPathFolder & "psexec.exe"
End If
Next
If booPSExecInPath = False Then
If UBound(arrPaths) < 21 Then
For i = 0 To UBound(arrPaths)
strPathFolder = arrPaths(i) & "\"
strPathFolder = Replace(strPathFolder, "\\", "\")
strPathFolder = Replace(LCase(strPathFolder), "%systemroot%", _
objShell.ExpandEnvironmentStrings("%systemroot%"))
strHTML = strHTML & LCase(strPathFolder) & "<br />"
Next
Else strHTML = strHTML & strPath & "<br />"
End If
SystemPathSpan.InnerHTML = strHTML
ShowDiv(NoPSExecArea)
Exit Sub
End If
PreviewstrPCSpan.InnerHTML = strPC
strPSExecLocationSpan.InnerHTML = strPSExecLocation
ShowDiv(DataArea)
PopulatePSExecSaveList(txtComputerName.Value)
End Sub
'#--------------------------------------------------------------------------
'# SUBROUTINE.....: PopulatePSExecSaveList(strPC)
'# PURPOSE........: Populates the PSExec save list drop down box
'# ARGUMENTS......: strPC = PC on which to perform action
'# EXAMPLE........: PopulatePSExecSaveList(PC1)
'# NOTES..........:
'#--------------------------------------------------------------------------
Sub PopulatePSExecSaveList(strPC)
On Error Resume Next
Dim arrPSExecSaves(9)
arrPSExecSaves(0) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave01")
arrPSExecSaves(1) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave02")
arrPSExecSaves(2) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave03")
arrPSExecSaves(3) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave04")
arrPSExecSaves(4) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave05")
arrPSExecSaves(5) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave06")
arrPSExecSaves(6) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave07")
arrPSExecSaves(7) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave08")
arrPSExecSaves(8) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave09")
arrPSExecSaves(9) = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave10")
For Each objOption in SaveList.Options
objOption.RemoveNode
Next
Set objOption = Document.createElement("OPTION")
objOption.Text = ""
objOption.Value = ""
SaveList.Add(objOption)
For i = 0 To 9
If arrPSExecSaves(i) <> "" Then
strCheckString = ""
strPSExecSaveString = Replace(arrPSExecSaves(i), "strPC", strPC)
arrPSExecSaveName = Split(strPSExecSaveString, "}{")
strPSExecSaveName = arrPSExecSaveName(0)
strPSExecSaveCommand = arrPSExecSaveName(1)
strPSExecSaveVariables = arrPSExecSaveName(2)
If strPSExecSaveVariables <> "" AND strPSExecSaveVariables <> " " Then _
strPSExecSaveName = strPSExecSaveName & " " & strPSExecSaveVariables
If InStr(LCase(strPSExecSaveCommand), "%comspec% /k") > 0 Then _
strPSExecSaveName = strPSExecSaveName & " (Keep CMD)"
strTitle = strPSExecSaveName
Set objOption = Document.createElement("OPTION")
objOption.Text = strPSExecSaveName
objOption.Value = strPSExecSaveString
objOption.Title = strTitle
SaveList.Add(objOption)
End If
Next
End Sub
'#--------------------------------------------------------------------------
'# SUBROUTINE.....: OpenPSExecCommand(strPC)
'# PURPOSE........: Opens the command specified in the PSExec save list
'# ARGUMENTS......: strPC = PC on which to perform action
'# EXAMPLE........: OpenPSExecCommand(PC1)
'# NOTES..........:
'#--------------------------------------------------------------------------
Sub OpenPSExecCommand(strPC)
strCheckCommand = ""
ClearPSExecCommands txtComputerName.Value
If SaveList.Value <> "" Then
strSaveString = SaveList.Value
arrSaveString = Split(strSaveString, "}{")
strPreviewSaveCommand = arrSaveString(0)
strExecuteSaveCommand = LCase(arrSaveString(1))
strVariables = LCase(arrSaveString(2))
arrCheckCommand = Split(strExecuteSaveCommand, " ")
For i = 0 To UBound(arrCheckCommand)
strCheckCommand = strCheckCommand & arrCheckCommand(i) & " "
If LCase(arrCheckCommand(i)) = "\\" & LCase(strPC) Then Exit For
Next
arrUserValue = Split(strPreviewSaveCommand, " ")
If InStr(strCheckCommand, "-i") > 0 Then Commands.cbxInteractive.Checked = True
If InStr(LCase(strExecuteSaveCommand), "%comspec% /k") > 0 Then Commands.cbxCMD.Checked = True
If InStr(strCheckCommand, "-e") > 0 Then Commands.cbxNotLoadProf.Checked = True
If InStr(strCheckCommand, "-s") > 0 Then Commands.cbxSystem.Checked = True
If InStr(strCheckCommand, "-s") > 0 Then
Commands.cbxSystem.Checked = True
Commands.cbxUsername.Disabled = True
End If
If InStr(strCheckCommand, "-c") > 0 Then
Commands.cbxCopyFile.Checked = True
Commands.cbxForceCopy.Disabled = False
Commands.cbxNewerFile.Disabled = False
End If
If InStr(strCheckCommand, "-f") > 0 Then Commands.cbxForceCopy.Checked = True
If InStr(strCheckCommand, "-v") > 0 Then Commands.cbxNewerFile.Checked = True
If InStr(strCheckCommand, "-low") > 0 Then _
Commands.PriorityChooser.Value = "low"
If InStr(strCheckCommand, "-belownormal") > 0 Then _
Commands.PriorityChooser.Value = "belownormal"
If InStr(strCheckCommand, "-abovenormal") > 0 Then _
Commands.PriorityChooser.Value = "abovenormal"
If InStr(strCheckCommand, "-high") > 0 Then _
Commands.PriorityChooser.Value = "high"
If InStr(strCheckCommand, "-realtime") > 0 Then _
Commands.PriorityChooser.Value = "realtime"
If InStr(strCheckCommand, "-u") > 0 Then
Commands.cbxUsername.Checked = True
For i = 0 to UBound(arrUserValue)
If arrUserValue(i) = "-u" Then Commands.txtUsername.Value = arrUserValue(i + 1)
Next
Commands.txtPassword.Value = "******"
Commands.txtUsername.className = "text"
Commands.txtPassword.className = "text"
Commands.txtUsername.Disabled = False
Commands.txtPassword.Disabled = False
Commands.cbxNotLoadProf.Disabled = False
Commands.cbxSystem.Disabled = True
End If
For i = 0 to UBound(arrUserValue)
If LCase(arrUserValue(i)) = "\\" & LCase(strPC) Then
For x = i + 1 To UBound(arrUserValue)
Commands.txtCommand.Value = Commands.txtCommand.Value & arrUserValue(x) & " "
Next
Exit For
End If
Next
Commands.txtVariables.Value = strVariables
ExecutePSExecCommand strPC, False, False, True
End If
End Sub
'#--------------------------------------------------------------------------
'# SUBROUTINE.....: UpdatePSExecSaveCommands(strSaveString)
'# PURPOSE........: Adds the current PSExec command into save list
'# registry value
'# ARGUMENTS......: strSaveString = string value to be saved in
'# registry
'# EXAMPLE........: UpdatePSExecSaveCommands("Preview}{Execute}")
'# NOTES..........: Allows 10 commands to be saved
'#--------------------------------------------------------------------------
Sub UpdatePSExecSaveCommands(strSaveString)
On Error Resume Next
strSaveString = Trim(strSaveString)
strPSExecSave01 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave01")
strPSExecSave02 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave02")
strPSExecSave03 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave03")
strPSExecSave04 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave04")
strPSExecSave05 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave05")
strPSExecSave06 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave06")
strPSExecSave07 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave07")
strPSExecSave08 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave08")
strPSExecSave09 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave09")
strPSExecSave10 = objShell.RegRead("HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave10")
If strPSExecSave10 = "" Then
objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave10", strSaveString, "REG_SZ"
PopulatePSExecSaveList(txtComputerName.Value)
Exit Sub
End If
If strPSExecSave09 = "" Then
If strPSExecSave10 <> strSaveString Then
objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave09", _
strSaveString, "REG_SZ"
PopulatePSExecSaveList(txtComputerName.Value)
Exit Sub
End If
End If
If strPSExecSave08 = "" Then
If strPSExecSave10 <> strSaveString Then
If strPSExecSave09 <> strSaveString Then
objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave08", _
strSaveString, "REG_SZ"
PopulatePSExecSaveList(txtComputerName.Value)
Exit Sub
End If
End If
End If
If strPSExecSave07 = "" Then
If strPSExecSave10 <> strSaveString Then
If strPSExecSave09 <> strSaveString Then
If strPSExecSave08 <> strSaveString Then
objShell.RegWrite _
"HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave07", _
strSaveString, "REG_SZ"
PopulatePSExecSaveList(txtComputerName.Value)
Exit Sub
End If
End If
End If
End If
If strPSExecSave06 = "" Then
If strPSExecSave10 <> strSaveString Then
If strPSExecSave09 <> strSaveString Then
If strPSExecSave08 <> strSaveString Then
If strPSExecSave07 <> strSaveString Then
objShell.RegWrite _
"HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave06", _
strSaveString, "REG_SZ"
PopulatePSExecSaveList(txtComputerName.Value)
Exit Sub
End If
End If
End If
End If
End If
If strPSExecSave05 = "" Then
If strPSExecSave10 <> strSaveString Then
If strPSExecSave09 <> strSaveString Then
If strPSExecSave08 <> strSaveString Then
If strPSExecSave07 <> strSaveString Then
If strPSExecSave06 <> strSaveString Then
objShell.RegWrite _
"HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave05", _
strSaveString, "REG_SZ"
PopulatePSExecSaveList(txtComputerName.Value)
Exit Sub
End If
End If
End If
End If
End If
End If
If strPSExecSave04 = "" Then
If strPSExecSave10 <> strSaveString Then
If strPSExecSave09 <> strSaveString Then
If strPSExecSave08 <> strSaveString Then
If strPSExecSave07 <> strSaveString Then
If strPSExecSave06 <> strSaveString Then
If strPSExecSave05 <> strSaveString Then
objShell.RegWrite _
"HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave04", _
strSaveString, "REG_SZ"
PopulatePSExecSaveList(txtComputerName.Value)
Exit Sub
End If
End If
End If
End If
End If
End If
End If
If strPSExecSave03 = "" Then
If strPSExecSave10 <> strSaveString Then
If strPSExecSave09 <> strSaveString Then
If strPSExecSave08 <> strSaveString Then
If strPSExecSave07 <> strSaveString Then
If strPSExecSave06 <> strSaveString Then
If strPSExecSave05 <> strSaveString Then
If strPSExecSave04 <> strSaveString Then
objShell.RegWrite _
"HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave03", _
strSaveString, "REG_SZ"
PopulatePSExecSaveList(txtComputerName.Value)
Exit Sub
End If
End If
End If
End If
End If
End If
End If
End If
If strPSExecSave02 = "" Then
If strPSExecSave10 <> strSaveString Then
If strPSExecSave09 <> strSaveString Then
If strPSExecSave08 <> strSaveString Then
If strPSExecSave07 <> strSaveString Then
If strPSExecSave06 <> strSaveString Then
If strPSExecSave05 <> strSaveString Then
If strPSExecSave04 <> strSaveString Then
If strPSExecSave03 <> strSaveString Then
objShell.RegWrite _
"HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave02", _
strSaveString, "REG_SZ"
PopulatePSExecSaveList(txtComputerName.Value)
Exit Sub
End If
End If
End If
End If
End If
End If
End If
End If
End If
If strPSExecSave01 = "" Then
If strPSExecSave10 <> strSaveString Then
If strPSExecSave09 <> strSaveString Then
If strPSExecSave08 <> strSaveString Then
If strPSExecSave07 <> strSaveString Then
If strPSExecSave06 <> strSaveString Then
If strPSExecSave05 <> strSaveString Then
If strPSExecSave04 <> strSaveString Then
If strPSExecSave03 <> strSaveString Then
If strPSExecSave02 <> strSaveString Then
objShell.RegWrite _
"HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave01", _
strSaveString, "REG_SZ"
PopulatePSExecSaveList(txtComputerName.Value)
Exit Sub
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
If strPSExecSave01 = strSaveString Then Exit Sub
If strPSExecSave02 = strSaveString Then Exit Sub
If strPSExecSave03 = strSaveString Then Exit Sub
If strPSExecSave04 = strSaveString Then Exit Sub
If strPSExecSave05 = strSaveString Then Exit Sub
If strPSExecSave06 = strSaveString Then Exit Sub
If strPSExecSave07 = strSaveString Then Exit Sub
If strPSExecSave08 = strSaveString Then Exit Sub
If strPSExecSave09 = strSaveString Then Exit Sub
If strPSExecSave10 = strSaveString Then Exit Sub
objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave01", strSaveString, "REG_SZ"
objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave02", strPSExecSave01, "REG_SZ"
objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave03", strPSExecSave02, "REG_SZ"
objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave04", strPSExecSave03, "REG_SZ"
objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave05", strPSExecSave04, "REG_SZ"
objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave06", strPSExecSave05, "REG_SZ"
objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave07", strPSExecSave06, "REG_SZ"
objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave08", strPSExecSave07, "REG_SZ"
objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave09", strPSExecSave08, "REG_SZ"
objShell.RegWrite "HKCU\Software\SKB\PSExecCommandBuilder\strPSExecSave10", strPSExecSave09, "REG_SZ"
PopulatePSExecSaveList(txtComputerName.Value)
End Sub
'#--------------------------------------------------------------------------
'# SUBROUTINE.....: ExecutePSExecSaveCommands(strPC, booRun, booSave, booOpen)
'# PURPOSE........: Executes the PSExec command specified
'# ARGUMENTS......: strPC = PC on which to perform action
'# booRun = boolean value to determine whether to
'# execute command (True) or not (False)
'# booSave = boolean value to determine whether to
'# Save command (True) or not (False)
'# booOpen = boolean value to determine whether to
'# Open command (True) or not (False)
'# EXAMPLE........: ExecutePSExecSaveCommands PC1, True, False, False
'# NOTES..........:
'#--------------------------------------------------------------------------
Sub ExecutePSExecCommand(strPC, booRun, booSave, booOpen)
strPSExec = "psexec.exe "
strComputer = "\\" & strPC & " "
If Commands.txtCommand.Value <> "" Then
strCommand = Trim(Commands.txtCommand.Value)
If InStr(strCommand, " ") > 0 AND InStr(strCommand,Chr(34)) = 0 Then
strCommand = Chr(34) & strCommand & Chr(34) & " "
Else
strCommand = strCommand & " "
End If
End If
If Commands.txtVariables.Value <> "" Then _
strVariables = " " & Commands.txtVariables.Value
If Commands.cbxInteractive.Checked Then
If InStr(strSwitches, "-i") = 0 Then strSwitches = strSwitches & "-i "
Else
strSwitches = Replace(strSwitches, "-i", "")
End If
If Commands.cbxCMD.Checked Then
strCMD = "%COMSPEC% /k "
Else
strCMD = ""
End If
If Commands.cbxNotLoadProf.Checked Then
If InStr(strSwitches, "-e") = 0 Then strSwitches = strSwitches & "-e "
Else
strSwitches = Replace(strSwitches, "-e", "")
End If
If Commands.cbxSystem.Checked Then
If InStr(strSwitches, "-s") = 0 Then strSwitches = strSwitches & "-s "
Commands.cbxUsername.Checked = False
Commands.cbxUsername.Disabled = True
Else
Commands.cbxUsername.Disabled = False
strSwitches = Replace(strSwitches, "-s", "")
End If
If Commands.cbxCopyFile.Checked Then
If InStr(strSwitches, "-c") = 0 Then strSwitches = strSwitches & "-c "
Commands.cbxForceCopy.Disabled = False
Commands.cbxNewerFile.Disabled = False
Else
strSwitches = Replace(strSwitches, "-c", "")
Commands.cbxForceCopy.Disabled = True
Commands.cbxForceCopy.Checked = False
Commands.cbxNewerFile.Disabled = True
Commands.cbxNewerFile.Checked = False
End If
If Commands.cbxForceCopy.Checked Then
If InStr(strSwitches, "-f") = 0 Then strSwitches = strSwitches & "-f "
Else
strSwitches = Replace(strSwitches, "-f", "")
End If
If Commands.cbxNewerFile.Checked Then
If InStr(strSwitches, "-v") = 0 Then strSwitches = strSwitches & "-v "
Else
strSwitches = Replace(strSwitches, "-v", "")
End If
If Commands.PriorityChooser.Value <> "0" then
strPriority = "-" & Commands.PriorityChooser.Value & " "
End If
If Commands.cbxUsername.Checked Then
Commands.txtUsername.className = "text"
Commands.txtPassword.className = "text"
Commands.txtUsername.Disabled = False
Commands.txtPassword.Disabled = False
Commands.cbxNotLoadProf.Disabled = False
Commands.cbxSystem.Checked = False
Commands.cbxSystem.Disabled = True
On Error Goto 0
If SaveList.Value <> "" Then
strSaveString = SaveList.Value
arrSaveString = Split(strSaveString, "}{")
strExecuteCommand = arrSaveString(1)
arrExecuteCommand = Split(strExecuteCommand, " ")
For i = 0 To UBound(arrExecuteCommand)
If arrExecuteCommand(i) = "-p" Then
strPassword = arrExecuteCommand(i + 1)
Exit For
End If
Next
Commands.txtPassword.Value = strPassword
End If
If Commands.txtUsername.Value = "" Then
strLoggedOn = LoggedOnUser(".")
Commands.txtUsername.Value = strLoggedOn
End If
strUserName = "-u " & Commands.txtUsername.Value & " "
If Commands.txtPassword.Value <> "" Then
strUserVisiblePass = "-p ****** "
strUserPass = "-p " & Commands.txtPassword.Value & " "
End If
Else
Commands.txtUsername.className = "text disabled"
Commands.txtPassword.className = "text disabled"
Commands.txtUsername.Disabled = True
Commands.txtPassword.Disabled = True
Commands.cbxNotLoadProf.Disabled = True
Commands.cbxSystem.Disabled = False
Commands.txtUsername.Value = ""
Commands.txtPassword.Value = ""
End If
strVisibleCommand = strPSExec & strSwitches & strUserName & strUserVisiblePass & _
strPriority & strComputer & strCommand & strVariables
strExecuteCommand = strPSExec & strSwitches & strUserName & _
strUserPass & strPriority & strComputer & strCMD & strCommand & strVariables
PreviewCommand.InnerHTML = strVisibleCommand
If booOpen = False Then SaveList.Value = ""
If booSave = True Then
If strUserPass <> "" Then
PWPrompt = MsgBox("The password provided will be stored in clear text." & _
vbCrLf & vbCrLf & "Are you sure you wish to do this?",vbYesNo+vbExclamation, _
"PSExec Command Builder")
If PWPrompt = vbNo Then
Exit Sub
End If
End If
strPreviewSaveCommand = Replace(strVisibleCommand, strPC, "strPC")
strExecuteSaveCommand = Replace(strExecuteCommand, strPC, "strPC")
If strVariables <> "" AND strVariables <> " " Then
strPreviewSaveCommand = Replace(strPreviewSaveCommand, strVariables, "")
strExecuteSaveCommand = Replace(strExecuteSaveCommand, strVariables, "")
Else
strVariables = ""
End If
strSaveString = Trim(strPreviewSaveCommand) & "}{" & Trim(strExecuteSaveCommand) & _
"}{" & Trim(strVariables)
UpdatePSExecSaveCommands(strSaveString)
End If
If booRun = True Then
objShell.Run "%COMSPEC% /c " & strExecuteCommand
End If
End Sub
'#--------------------------------------------------------------------------
'# SUBROUTINE.....: ClearPSExecCommands(strPC)
'# PURPOSE........: Clears the PSExec form / preview
'# ARGUMENTS......: strPC = PC on which to perform action
'# EXAMPLE........: ClearPSExecCommandsPC1)
'# NOTES..........:
'#--------------------------------------------------------------------------
Sub ClearPSExecCommands(strPC)
With Commands
.txtCommand.Value = ""
.txtVariables.Value = ""
.txtUsername.Value = ""
.txtPassword.Value = ""
.txtUsername.className = "text disabled"
.txtPassword.className = "text disabled"
.txtUsername.Disabled = True
.txtPassword.Disabled = True
.cbxInteractive.Checked = False
.cbxNotLoadProf.Disabled = True
.cbxNotLoadProf.Checked = False
.cbxSystem.Disabled = False
.cbxSystem.Checked = False
.cbxCopyFile.Checked = False
.cbxForceCopy.Checked = False
.cbxForceCopy.Disabled = True
.cbxNewerFile.Checked = False
.cbxNewerFile.Disabled = True
.cbxUsername.Checked = False
.cbxUsername.Disabled = False
.cbxCMD.Checked = False
.PriorityChooser.Value = 0
End With
PreviewCommand.InnerHTML = "psexec.exe \\" & strPC
End Sub
'#--------------------------------------------------------------------------
'# SUBROUTINE.....: CopyPSExecCommand()
'# PURPOSE........: Copies the content of the Preview area to the
'# clipboard
'# ARGUMENTS......:
'# EXAMPLE........:
'# NOTES..........:
'#--------------------------------------------------------------------------
Sub CopyPSExecCommand()
strCopy = PreviewCommand.InnerHTML
document.parentwindow.clipboardData.SetData "text", strCopy
MsgBox "The command has now been copied to the clipboard",vbInformation,"PSExec Command Builder"
End Sub
'#--------------------------------------------------------------------------
'# SUBROUTINE.....: ChangeUser()
'# PURPOSE........: Action triggered on changing value in textbox
'# ARGUMENTS......:
'# EXAMPLE........:
'# NOTES..........:
'#--------------------------------------------------------------------------
Sub ChangeUser()
ClearPSExecCommands(txtComputerName.Value)
ShowDiv(0)
End Sub
'#--------------------------------------------------------------------------
'# SUBROUTINE.....: ShowDiv(objDiv)
'# PURPOSE........: Changes display to show required screen
'# ARGUMENTS......: objDiv = html div to show
'# EXAMPLE........: ShowDiv(DataArea)
'# NOTES..........:
'#--------------------------------------------------------------------------
Sub ShowDiv(objDiv)
On Error Resume Next
DataArea.className = "hidden"
NotFoundArea.className = "hidden"
NoPSExecArea.className = "hidden"
objDiv.className = ""
End Sub
'#--------------------------------------------------------------------------
'# SUBROUTINE.....: Window_onLoad()
'# PURPOSE........: Performs onLoad actions
'# ARGUMENTS......:
'# EXAMPLE........:
'# NOTES..........:
'#--------------------------------------------------------------------------
Sub Window_onLoad
self.ResizeTo 700,465
VersionSpan.InnerHTML = objPSExecCommandBuilder.Version
window.moveTo intLeft,intTop
End Sub
'#--------------------------------------------------------------------------
'# FUNCTION.......: Reachable(strPC)
'# PURPOSE........: Checks whether the remote PC is online
'# ARGUMENTS......: strPC = PC on which to perform action
'# EXAMPLE........: Reachable(PC1)
'# NOTES..........:
'#--------------------------------------------------------------------------
Function Reachable(strPC)
Set objWMIService2 = GetObject("winmgmts:\\.\root\cimv2")
Set colPing = objWMIService2.ExecQuery _
("Select * from Win32_PingStatus Where Address = '" & strPC & "'")
For Each objItem in colPing
If IsNull(objItem.StatusCode) Or objItem.Statuscode <> 0 Then
Reachable = False
Else
Reachable = True
End If
Next
End Function
'#--------------------------------------------------------------------------
'# FUNCTION.......: LoggedOnUser(strPC)
'# PURPOSE........: Get the name of the logged on user as per WMI
'# ARGUMENTS......: strPC = PC on which to perform action
'# EXAMPLE........: LoggedOnUser(PC1)
'# NOTES..........:
'#--------------------------------------------------------------------------
Function LoggedOnUser(strPC)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strPC & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objItem In colComputer
strLoggedOn = objItem.UserName
Next
LoggedOnUser = strLoggedOn
End Function
</script>
<body>
<table width="100%">
<tr>
<td>
Computer Name:
<input type="text" class="text" style="border-right:0px;border-width:2px;" tabindex="1" id="txtComputerName" size="15" onKeyUp="ChangeUser()"><input id="RunButton" class="button" type="button" style="height:23px;" tabindex="2" value="Select PC" name="btnCheck" onclick="RunPSExecCommand()" onMouseOver="btnCheck.className='button btnhov'" onMouseOut="btnCheck.className='button'">
</td>
<td style="text-align:right;font-size:0.9em;font-style:italic;font-weight:bold;font-size:0.9em;color:#888888;">
Version <span id=VersionSpan> </span>   Created by Stuart Barrett
</td>
</tr>
</table>
<hr>
<div id="DataArea" class="hidden">
<div style="font-size:0.9em;font-style:italic;font-weight:bold;color:#888888;">
Logged On User: <span id="LoggedOnSpan"> </span>
</div>
<form name="Commands" method ="post">
<table id="CommandsTable" style="width:100%;margin-top:0px;">
<tr>
<td>
<table style="width:100%;">
<tr>
<td title="Command to be run">
Command:
</td>
<td title="Command to be run">
<input type="text" class="text" name="txtCommand" size="32" onKeyUp="ExecutePSExecCommand txtComputerName.Value, False, False, False">
</td>
<td title="Command variables">
Variables:
</td>
<td title="Command variables">
<input type="text" class="text" name="txtVariables" size="32" onKeyUp="ExecutePSExecCommand txtComputerName.Value, False, False, False">
</td>
</tr>
<tr>
<td title="Optional user name for login to remote system">
Username:
</td>
<td title="Optional user name for login to remote system">
<input type="text" name="txtUsername" size="32" disabled=true class="text disabled" onKeyUp="ExecutePSExecCommand txtComputerName.Value, False, False, False">
</td>
<td title="Optional password for username, if left blank where a username is specified then you will be asked to supply one on executing the command">
Password:
</td>
<td title="Optional password for username, if left blank where a username is specified then you will be asked to supply one on executing the command">
<input type="password" name="txtPassword" size="32" class="text disabled" disabled=true onKeyUp="ExecutePSExecCommand txtComputerName.Value, False, False, False">
</td>
</tr>
</tr>
</table>
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td>
<table width="100%">
<tr>
<td style="width:30%;" title="Run the program so that it interacts with the desktop of the specified session on the remote system">
Interactive
</td>
<td style="width:3%;" title="Run the program so that it interacts with the desktop of the specified session on the remote system">
<input type="checkbox" name="cbxInteractive" onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
</td>
<td style="width:30%;" title="Does not load the specified account's profile">
Do not load user profile
</td>
<td style="width:3%;" title="Does not load the specified account's profile">
<input type="checkbox" name="cbxNotLoadProf" disabled=true onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
</td>
<td style="width:30%;" title="Run the remote process in the System account">
Run as System
</td>
<td style="width:3%;" title="Run the remote process in the System account">
<input type="checkbox" name="cbxSystem" onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
</td>
</tr>
<tr>
<td title="Copy the specified program to the remote system for execution">
Copy file to remote host
</td>
<td title="Copy the specified program to the remote system for execution">
<input type="checkbox" name="cbxCopyFile" onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
</td>
<td title="Copy the specified program even if the file already exists on the remote system">
Force copy
</td>
<td title="Copy the specified program even if the file already exists on the remote system">
<input type="checkbox" name="cbxForceCopy" disabled=true onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
</td>
<td title="Copy the specified file only if it has a higher version number or is newer than the one on the remote system">
Copy if file is newer
</td>
<td title="Copy the specified file only if it has a higher version number or is newer than the one on the remote system">
<input type="checkbox" name="cbxNewerFile" disabled=true onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
</td>
</tr>
<tr>
<td title="Optional user name for login to remote system">
Alternate Username
</td>
<td title="Optional user name for login to remote system">
<input type="checkbox" name="cbxUsername" onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
</td>
<td title="Carries out the command specified by string and then the command Window remains (eg. for ipconfig)">
Keep CMD on screen
</td>
<td title="Carries out the command specified by string and then the command Window remains (eg. for ipconfig)">
<input type="checkbox" name="cbxCMD" onClick="ExecutePSExecCommand txtComputerName.Value, False, False, False">
</td>
<td title="Change the priority at which the process is run" colspan="2">
Priority
<select size="1" name="PriorityChooser" style="width:154px" onChange="ExecutePSExecCommand txtComputerName.Value, False, False, False">
<option value="0"></option>
<option value="low">Low</option>
<option value="belownormal">Below Normal</option>
<option value="abovenormal">Above Normal</option>
<option value="high">High</option>
<option value="realtime">Realtime</option>
</select>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<p>
Preview:
<span style="background-color:white;width:100%;height:50px;border:1px solid black;padding:5px;" id="PreviewCommand">
psexec.exe \\<span id="PreviewstrPCSpan"> </span>
</span>
<p>
<span style="float:left">
<input id="runbutton" class="button" type="button" value="Execute" name="btnExecute" title="Execute command on PC" style="width:75px;" onClick="ExecutePSExecCommand txtComputerName.Value, True, False, False" onMouseOver="btnExecute.className='button btnhov'" onMouseOut="btnExecute.className='button'">
<input id="runbutton" class="button" type="button" value="Clear" name="btnPSClear" title="Clear all PS Exec Commands" style="width:60px;border-right:0px;" onClick="ClearPSExecCommands txtComputerName.Value" onMouseOver="btnPSClear.className='button btnhov'" onMouseOut="btnPSClear.className='button'"><input id="runbutton" class="button" type="button" value="Copy" name="btnPSCopy" title="Copy PS Exec Command to clipboard" style="width:60px;border-right:0px;" onClick="CopyPSExecCommand" onMouseOver="btnPSCopy.className='button btnhov'" onMouseOut="btnPSCopy.className='button'"><input id="runbutton" class="button" type="button" value="Save" name="btnPSSave" title="Save PSExec command for future use" style="width:60px;" onClick="ExecutePSExecCommand txtComputerName.Value, False, True, False" onMouseOver="btnPSSave.className='button btnhov'" onMouseOut="btnPSSave.className='button'">
</span>
<span style="float:right;">
Saved Commands:
<select size="1" name="SaveList" style="width:250px;" onChange="OpenPSExecCommand(txtComputerName.Value)">
</select>
</span>
</p>
<div style="font-style:italic;position:absolute;bottom:5px;right:10px;">
<span style="font-weight:bold;">PSExec Location:</span>
<span id="strPSExecLocationSpan"> </span>
</div>
</div>
<div id="NotFoundArea" class="hidden">
<span style="font-size:1.75em;font-weight:bold;color:red;">Access Error</span>
<p>
This PC cannot be reached or the Computer Name has been entered incorrectly.
</p>
<p>
Please make sure you have entered the Computer Name correctly and try again.
</p>
</div>
<div id="NoPSExecArea" class="hidden">
<span style="font-size:1.75em;font-weight:bold;color:red;">PSExec Missing</span>
<p>
PSExec cannot be found in the System Path. The folders within your System Path are as below:
</p>
<span id="SystemPathSpan" style="height:170px;width:100%;overflow:auto;border:1px solid black;padding:5px;"> </span>
<br />
You can download this utility from the following location:
<p style="margin-top:5px;">
<a href="http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx" title="Download PSExec" target="_blank">
http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
</a>
</p>
Once you have downloaded PSExec you must place it into one of the above mentioned folders.
</div>
</body>
</html> |
Partager