Roebuck1967
asked on
I need a VB script that uses the RenComp.exe tool
Would like to add sort of a GUI to RenComp.exe. Script should
1 – Ask for old computer name
2 – Then ask for new computer name
3 – Rename computer name and give a pop up confirmation
4- Prompt for next computer name and log all successful & unsuccessful attempts
Old script notes:
Dim objExcel, strPathExcel, objFile
Dim fso, ts, fso2, ts2
Const ForWriting = 8
Const ForReading = 1
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Set objExcel = CreateObject("Excel.Applic ation")
strPathExcel = "\\DS\ADLookup\ADLookupR.x ls"
objExcel.Workbooks.open strPathExcel
Set objSheet = objExcel.ActiveWorkbook.Wo rksheets(1 )
Set SH = CreateObject("WScript.Shel l")
row = 1
newName = ""
Do While Trim(objSheet.cells(row, 1).Value) <> ""
CName = objSheet.cells(row, 1)
newName = Trim(objSheet.cells(row, 5).Value)
If objSheet.cells(row, 6) <> "CHANGED" Then
SH.Run "cmd /c RENCOMP " + CName + " " + newName + " >c:\temp.tmp", 1, True
Set ts = fso.OpenTextFile("c:\temp. tmp", ForReading, True)
a = ts.ReadLine()
ts.Close
If InStr(a, "Failed") > 0 Then
MsgBox ("Failed to rename " + CName + " to " + newName + "!")
objSheet.cells(row, 6) = ""
objSheet.cells(row, 7) = ""
Else
MsgBox ("Successfully renamed " + CName + " to " + newName + "!")
objSheet.cells(row, 6) = "CHANGED"
objSheet.cells(row, 7) = Trim(CStr(Now))
End If
End If
row = row + 1
Loop
objExcel.ActiveWorkbook.Sa ve
objExcel.ActiveWorkbook.Cl ose
MsgBox ("Script complete.")
1 – Ask for old computer name
2 – Then ask for new computer name
3 – Rename computer name and give a pop up confirmation
4- Prompt for next computer name and log all successful & unsuccessful attempts
Old script notes:
Dim objExcel, strPathExcel, objFile
Dim fso, ts, fso2, ts2
Const ForWriting = 8
Const ForReading = 1
Set fso = CreateObject("Scripting.Fi
Set objExcel = CreateObject("Excel.Applic
strPathExcel = "\\DS\ADLookup\ADLookupR.x
objExcel.Workbooks.open strPathExcel
Set objSheet = objExcel.ActiveWorkbook.Wo
Set SH = CreateObject("WScript.Shel
row = 1
newName = ""
Do While Trim(objSheet.cells(row, 1).Value) <> ""
CName = objSheet.cells(row, 1)
newName = Trim(objSheet.cells(row, 5).Value)
If objSheet.cells(row, 6) <> "CHANGED" Then
SH.Run "cmd /c RENCOMP " + CName + " " + newName + " >c:\temp.tmp", 1, True
Set ts = fso.OpenTextFile("c:\temp.
a = ts.ReadLine()
ts.Close
If InStr(a, "Failed") > 0 Then
MsgBox ("Failed to rename " + CName + " to " + newName + "!")
objSheet.cells(row, 6) = ""
objSheet.cells(row, 7) = ""
Else
MsgBox ("Successfully renamed " + CName + " to " + newName + "!")
objSheet.cells(row, 6) = "CHANGED"
objSheet.cells(row, 7) = Trim(CStr(Now))
End If
End If
row = row + 1
Loop
objExcel.ActiveWorkbook.Sa
objExcel.ActiveWorkbook.Cl
MsgBox ("Script complete.")
No offence - but why arnt you asking this in the VB TA?
ASKER
Because only one person can answer this question and he knows where to find it.
ASKER
Feel free to move it to VB
looks like someone beat me to it... Hope you find more contributions here in VB.
Cheers,
-Jon
Cheers,
-Jon
Hi guys!
Yeah, I was looking in the Networking section, Roebuck1967, but I didnt see your new question! I've been thinking you might move these over to VB so you'd be more likely to get help, as long as they're not too networking-involved. Buy anyway...
This new script you want, it sounds easy enough, but let can you clarify a few things...
1) Do you no longer want to use the excel file as your source for computer names?
2) How do you want to log attempts? Excel or text file?
3) How many times should the script prompt for computer names?
Yeah, I was looking in the Networking section, Roebuck1967, but I didnt see your new question! I've been thinking you might move these over to VB so you'd be more likely to get help, as long as they're not too networking-involved. Buy anyway...
This new script you want, it sounds easy enough, but let can you clarify a few things...
1) Do you no longer want to use the excel file as your source for computer names?
2) How do you want to log attempts? Excel or text file?
3) How many times should the script prompt for computer names?
ASKER
YohanShminge,
1 - Would like to start with a fresh excel file
2 - Via excel
3 - Prompt until cancel is selected
Would loke to have this a click option on my computer that would exicute
1 - Would like to start with a fresh excel file
2 - Via excel
3 - Prompt until cancel is selected
Would loke to have this a click option on my computer that would exicute
OK, I think this is what you want.
-------------------------- ------
Dim objExcel, strPathExcel, objFile
Dim fso, ts, fso2, ts2
Const ForReading = 1
Set objExcel = CreateObject("Excel.Applic ation")
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Set SH = CreateObject("WScript.Shel l")
strPathExcel = "C:\changelog.xls"
objExcel.Workbooks.open strPathExcel
Set objSheet = objExcel.ActiveWorkbook.Wo rksheets(1 )
Do
currentC = InputBox("Please enter the current computer name.")
If currentC = "" Then
objExcel.ActiveWorkbook.Cl ose
WScript.Quit
End If
newC = InputBox("Please enter the new computer name.")
If newC = "" Then
objExcel.ActiveWorkbook.Cl ose
WScript.Quit
End If
SH.Run "cmd /c C:\RENCOMP " + currentC + " " + newC + " >c:\temp.tmp", 1, True
Set ts = fso.OpenTextFile("c:\temp. tmp", ForReading, True)
a = ts.ReadLine()
ts.Close
For row = 1 To 10000
If objSheet.cells(row, 1) = "" Then Exit For
Next
If InStr(a, "Failed") > 0 Then
MsgBox ("Failed to rename " + currentC + " to " + newC + "!")
objSheet.cells(row, 1) = "FAILED"
objSheet.cells(row, 2) = currentC
objSheet.cells(row, 3) = newC
objSheet.cells(row, 4) = Trim(CStr(Now))
Else
MsgBox ("Successfully renamed " + currentC + " to " + newC + "!")
objSheet.cells(row, 1) = "CHANGED"
objSheet.cells(row, 2) = currentC
objSheet.cells(row, 3) = newC
objSheet.cells(row, 4) = Trim(CStr(Now))
End If
objExcel.ActiveWorkbook.Sa ve
Loop Until currentC = ""
--------------------------
Dim objExcel, strPathExcel, objFile
Dim fso, ts, fso2, ts2
Const ForReading = 1
Set objExcel = CreateObject("Excel.Applic
Set fso = CreateObject("Scripting.Fi
Set SH = CreateObject("WScript.Shel
strPathExcel = "C:\changelog.xls"
objExcel.Workbooks.open strPathExcel
Set objSheet = objExcel.ActiveWorkbook.Wo
Do
currentC = InputBox("Please enter the current computer name.")
If currentC = "" Then
objExcel.ActiveWorkbook.Cl
WScript.Quit
End If
newC = InputBox("Please enter the new computer name.")
If newC = "" Then
objExcel.ActiveWorkbook.Cl
WScript.Quit
End If
SH.Run "cmd /c C:\RENCOMP " + currentC + " " + newC + " >c:\temp.tmp", 1, True
Set ts = fso.OpenTextFile("c:\temp.
a = ts.ReadLine()
ts.Close
For row = 1 To 10000
If objSheet.cells(row, 1) = "" Then Exit For
Next
If InStr(a, "Failed") > 0 Then
MsgBox ("Failed to rename " + currentC + " to " + newC + "!")
objSheet.cells(row, 1) = "FAILED"
objSheet.cells(row, 2) = currentC
objSheet.cells(row, 3) = newC
objSheet.cells(row, 4) = Trim(CStr(Now))
Else
MsgBox ("Successfully renamed " + currentC + " to " + newC + "!")
objSheet.cells(row, 1) = "CHANGED"
objSheet.cells(row, 2) = currentC
objSheet.cells(row, 3) = newC
objSheet.cells(row, 4) = Trim(CStr(Now))
End If
objExcel.ActiveWorkbook.Sa
Loop Until currentC = ""
ASKER
YohanShminge
I receive the following error after I enter the new computer name
Line 28
Char 4
Error: Input past end file
code: 800A003E
I receive the following error after I enter the new computer name
Line 28
Char 4
Error: Input past end file
code: 800A003E
ASKER
YohanShminge
Scratch that last question - I have it working.
Would kike to tweek things a bit
1) When It prompts for the second computer name can you have "TAKING-" (without the quotes) in the field?
2) Anywhat to have the script promt Yes or No to remove the old name from the domain?
Thanks
Scratch that last question - I have it working.
Would kike to tweek things a bit
1) When It prompts for the second computer name can you have "TAKING-" (without the quotes) in the field?
2) Anywhat to have the script promt Yes or No to remove the old name from the domain?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
YohanShminge does it again. A million thanks!
ASKER
YohanShminge
You have done it again. A million thanks!
You have done it again. A million thanks!
So I take it the script worked? That's great!
ASKER
YohanShminge,
Long time - Hope all is well. I'm posting a new question today.
Long time - Hope all is well. I'm posting a new question today.