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
| <html>
<head>
<title>RenameComputer</title>
<script language="vbscript">
Option Explicit
Dim iRefreshRt, iTimerID
Sub Window_OnLoad
self.Focus()
'Resize the HTA and move
window.resizeTo 320, 340
window.moveTo screen.width/4, screen.height/4
End Sub
'Start monitoring, call Subs/Funcs
Sub StartRename
Dim strCurrentName, strNewName
'CheckFields for values
strCurrentName = window.document.getElementById("CurrentName").value
strNewName = window.document.getElementById("NewName").value
If Not ((IsEmpty(strCurrentName)) Or (IsNull(strCurrentName)) Or (IsEmpty(strNewName)) Or (IsNull(strNewName)) Or strCurrentName = "" Or strCurrentName = " " Or strNewName = "" Or strNewName = " ") Then
Call RenameComp (strCurrentName, strNewName)
Else
'48 + 1: 48 is ICON warning
Call ErrorMsg ("CurrentName or NewName field is missing")
End If
End Sub
Sub RenameComp (OldComp, NewComp)
Dim strCmd, objShell, iSec, RadioChoice, strPingStatus, strMsg
iSec = iTimer (Cint(DropMenu_iTimer.Value)) 'DropMenu Value, then calc FUNC
RadioChoice = RadioSelect() 'Check RadioSelect
strPingStatus = PingReply (OldComp)
Select Case strPingStatus
Case "ONLINE"
Set objShell = CreateObject("WScript.Shell") 'using .Run to supress cmd window
If RadioChoice = "ShutDown" Then
strCmd = ".\SystemFiles\netdom.exe renamecomputer " & OldComp & " " & "/newname:" & NewComp & _
" /ud:lahdsystems\helpdesk /passwordD:PasswordHere /force /reboot " & iSec
objShell.Run strCmd ,0 ,1
Else
strCmd = ".\SystemFiles\netdom.exe renamecomputer " & OldComp & " " & "/newname:" & NewComp & _
" /ud:lahdsystems\helpdesk /passwordD:lahd /force"
objShell.Run strCmd ,0 ,1
End If
strMsg = "Renaming attempt, please check status:" & vbCr & vbCr & _
" CurrentCompName = " & OldComp & vbCr & _
" NewCompName = " & NewComp
MsgBox strMsg, 64, "Renaming tool"
Case "OFFLINE"
Call ErrorMsg ("Computer is Offline/Unreachable")
End Select
End Sub
Function PingReply (strComputer)
Dim wmiQuery, objWMIService, objPing, objStatus
Dim strCmd, objShell, objExec, strRead, i, iReply
If Not ((IsEmpty(strComputer)) Or (IsNull(strComputer)) Or strComputer = "" Or strComputer = " ") Then
iReply = 0
'Define WMI query to ping
wmiQuery = "Select * From Win32_PingStatus Where " & _
"Address = '" & strComputer & "'"
'Make WMI connection to local machine
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objPing = objWMIService.ExecQuery(wmiQuery)
'Retrieve the status code of each ping request
For i = 1 To 2
Set objPing = objWMIService.ExecQuery(wmiQuery)
'Retrieve the status code of each ping request
For Each objStatus In objPing
'Return 0 for successful reply
If objStatus.StatusCode = 0 Then
iReply = iReply + 1
End If
Next
Next
'Win2k and below ping check
If iReply <= 0 Then
strCmd = "ping -n 2 -w 1000 " & strComputer
Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec(strCmd)
strRead = UCase(objExec.StdOut.ReadAll)
If InStr(strRead, "REPLY FROM") Then
iReply = iReply + 1
End If
End If
'Number of pings for PingStatus
Select Case True
Case (iReply <= 0)
PingReply = "OFFLINE"
Case Else
PingReply = "ONLINE"
End Select
End If
'Destroy VARs
Set objPing = Nothing
Set objWMIService = Nothing
iReply = Empty
strRead = Empty
End Function
Function RadioSelect()
Dim RadioVal
'Enum through Radio, check selected
Select Case True
Case RadioBtn(0).Checked
RadioVal = "ShutDown"
Case RadioBtn(1).Checked
RadioVal = "NoRestart"
End Select
'Assign SUB value
RadioSelect = RadioVal
End Function
Function ErrorMsg (msg)
MsgBox msg, 48, "Rename Error"
End Function
Function iTimer (TimeCheck)
iTimer = 60 * TimeCheck 'Calc for seconds
End Function
</script>
<hta:application
applicationname="RenameComputer"
border="dialog"
borderstyle="normal"
caption="RenameComputer"
contextmenu="no"
icon="images\icon.ico"
maximizebutton="no"
minimizebutton="yes"
navigable="no"
scroll="no"
selection="no"
showintaskbar="yes"
singleinstance="yes"
sysmenu="yes"
version="0.3"
windowstate="normal"
>
<style type="text/css">
a:link {
color:#000000;
font-size:12px;
font-family:"Times New Roman", Times, serif;
text-decoration:none;
font-style: normal;
font-variant: normal;
}
a:visited {
color:#000000;
font-size:12px;
font-family:"Times New Roman", Times, serif;
text-decoration:none;
font-style: normal;
font-variant: normal;
}
a:hover {
color:#000000;
font-size:12px;
font-family:"Times New Roman", Times, serif;
text-decoration:underline;
font-style: normal;
font-variant: normal;
}
td {
font-family: "Times New Roman", Times, serif;
font-size: 13px;
font-style: normal;
font-weight: normal;
font-variant: normal;
color:#000000;
vertical-align: center;
}
.status {
text-align:center;
}
</style>
</head>
<body STYLE="font:9pt arial; color:#000000; filter:progid:DXImageTransform.Microsoft.Gradient (GradientType=0, StartColorStr='#006d9f', EndColorStr='#ddd7ff')">
<table width="198" height="142" border="0" cellpadding="3">
<tr>
<!-- <td colspan="2">Banner</td> -->
<td colspan="2" align="Center"><font size="4" color="#FFFFB3"><strong>RenameComputer</strong></font></td>
</tr>
<tr valign="top">
<td width="90" height="51" align="Left">CurrentName<br>
<!-- Email address field -->
<input type="text" id="CurrentName" size="15"></td>
<td width="98" align="Left">NewName<br>
<!-- SMTP address field -->
<input type="text" id="NewName" size="15"></td>
</tr>
<tr valign="top">
<td align="Center"><input name="RadioBtn" type="radio" value="RadioButton1" checked>
ShutDown<br>
<input name="RadioBtn" type="radio" value="RadioButton2">
NoRestart </td>
<td align="Center" valign="middle">ShutdownTimer
<!-- DropDown onChange to Self.Focus() -->
<select size="1" name="DropMenu_iTimer" onChange="Window.Focus()">
<option value="1">1 min</option>
<option value="2" selected>2 min</option>
<option value="3">3 min</option>
<option value="4">4 min</option>
<option value="5">5 min</option>
<option value="6">6 min</option>
<option value="7">7 min</option>
<option value="7">8 min</option>
<option value="9">9 min</option>
<option value="10">10 min</option>
<option value="12">12 min</option>
<option value="15">15 min</option>
<option value="20">20 min</option>
<option value="30">30 min</option>
<option value="45">45 min</option>
<option value="60">60 min</option>
</select></td>
</tr>
<tr valign="top">
<td align="Center"> </td>
<td align="Center" valign="middle">
<!-- Submit button -->
<input type="button" value="Execute" onClick="StartRename">
</td>
</tr>
</table>
</body>
</html> |
Partager