»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 03-16-2004, 04:04 AM   #1 (permalink)
Registered User
 
muno's Avatar
 
Join Date: Oct 2001
Location: Finland
Posts: 3,838
muno is on a distinguished road
Send a message via Yahoo to muno
Script file creator with variables

Hi.

I'd like to be able to create similar files, with few variables.
It would be like this -> run the script, it asks for model as it appears in windows hcl, asks for ip, and based on my responds, creates one batch file and one reg file.

The files should contain the following static entries->
batch.cmd

regedit /s .\<model+ip from variables>.reg
net stop spooler
net start spooler
.\rundll32 printui.dll,PrintUIEntry /if /b "<Model from variable>" /f %windir%\inf\ntprint.inf /r "IP_<ip from variable>" /m "<Model from variable>"

reg.reg
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\Print\Monitors\Standard TCP/IP Port\Ports\IP_<ip from variable>]
"Protocol"=dword:00000001
"Version"=dword:00000001
"Hostname"=""
"HWAddress"=""
"IPAddress"="<ip from variable"
"PortNumber"=dword:0000238c
"SNMP Community"="public"
"SNMP Enabled"=dword:00000001
"SNMP Index"=dword:00000001

--end code

As everyone can see, I'm trying to automate the creation of an ip_port for a printer, and then add the printer to the newly created port.

If someone has a better way of doing it, please do tell. Please do not include any rootadministrator level ways to do it. I'm just a workstation administrator.

muno is offline   Reply With Quote
Old 03-16-2004, 04:57 AM   #2 (permalink)
Registered User
 
Join Date: Oct 2001
Location: TOO close to Wash DC
Posts: 7,956
vass0922 is on a distinguished road
This was created with a script I just put together in a few mins...

Look ok?
Filename 'epson127.0.0.1.reg'

Quote:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\Print\Monitors\Standard TCP/IP Port\Ports\IP_127.0.0.1]
"Protocol"=dword:00000001
"Version"=dword:00000001
"Hostname"=""
"HWAddress"=""
"IPAddress"="127.0.0.1"
"PortNumber"=dword:0000238c
"SNMP Community"="public"
"SNMP Enabled"=dword:00000001
"SNMP Index"=dword:00000001
ignore the line break in the HKLM key
__________________
<< Insert exceedingly large and overly verbose message of how 1337 you are here including full specs of every vehicle you've ever driven and PC you've owned >>
vass0922 is offline   Reply With Quote
Old 03-16-2004, 04:59 AM   #3 (permalink)
Registered User
 
muno's Avatar
 
Join Date: Oct 2001
Location: Finland
Posts: 3,838
muno is on a distinguished road
Send a message via Yahoo to muno
Sure it looks ok.
I forgot to put naming factors for the files (except in the batch file first line), the files should be name <model><ip address>.reg/cmd

Is it as easy to create the batch file?
muno is offline   Reply With Quote
Old 03-16-2004, 05:05 AM   #4 (permalink)
Registered User
 
Join Date: Oct 2001
Location: TOO close to Wash DC
Posts: 7,956
vass0922 is on a distinguished road
Ok this is the SHORT SHORT version

There are much better ways to do all of this, but I wrote for free in 10 mins

Code:
Dim objFSO
Dim objRegFile
Dim sGivenIP
Dim sGivenModel
Dim QUOTE_CHAR

QUOTE_CHAR = Chr(34)
sGivenModel = InputBox("Model of Desired Printer")
sGivenIP = InputBox("IP of desired Printer")

FOLDER_PATH = "C:\"
BATCH_FILE = sGivenModel & sGivenIP & ".bat"
REG_FILE = sGivenModel & sGivenIP & ".reg"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objRegFile = objFSO.CreateTextFile(FOLDER_PATH & REG_FILE, True)
Set objBatchFile = objFSO.CreateTextFile(FOLDER_PATH & BATCH_FILE, True)

objRegFile.WriteLine "Windows Registry Editor Version 5.00"
objRegFile.WriteLine "[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_" & sGivenIP & "]"
objRegFile.WriteLine QUOTE_CHAR & "Protocol" & QUOTE_CHAR & "=dword:00000001"
objRegFile.WriteLine QUOTE_CHAR & "Version" & QUOTE_CHAR & "=dword:00000001"
objRegFile.WriteLine QUOTE_CHAR & "Hostname" & QUOTE_CHAR & "=" & QUOTE_CHAR & QUOTE_CHAR
objRegFile.WriteLine QUOTE_CHAR & "HWAddress" & QUOTE_CHAR & "=" & QUOTE_CHAR & QUOTE_CHAR
objRegFile.WriteLine QUOTE_CHAR & "IPAddress" & QUOTE_CHAR & "=" & QUOTE_CHAR & sGivenIP & QUOTE_CHAR
objRegFile.WriteLine QUOTE_CHAR & "PortNumber" & QUOTE_CHAR & "=dword:0000238c"
objRegFile.WriteLine QUOTE_CHAR & "SNMP Community" & QUOTE_CHAR & "=" & QUOTE_CHAR & "public" & QUOTE_CHAR
objRegFile.WriteLine QUOTE_CHAR & "SNMP Enabled" & QUOTE_CHAR & "=dword:00000001"
objRegFile.WriteLine QUOTE_CHAR & "SNMP Index" & QUOTE_CHAR & "=dword:00000001"

objRegFile.Close

objBatchFile.WriteLine "regedit /s " & FOLDER_PATH & REG_FILE
objBatchFile.WriteLine "net stop spooler"
objBatchFile.WriteLine "net start spooler"
objBatchFile.WriteLine ".\rundll32 printui.dll,PrintUIEntry /if /b " & QUOTE_CHAR & sGivenModel & QUOTE_CHAR & " /f %windir%\inf\ntprint.inf /r " & QUOTE_CHAR & "IP_" & sGivenIP & QUOTE_CHAR & " /m " & sGivenModel
objBatchFile.Close
Edit the path for FOLDER_PATH to where you want the files to be created.

Good luck
__________________
<< Insert exceedingly large and overly verbose message of how 1337 you are here including full specs of every vehicle you've ever driven and PC you've owned >>
vass0922 is offline   Reply With Quote
Old 03-16-2004, 05:20 AM   #5 (permalink)
Registered User
 
muno's Avatar
 
Join Date: Oct 2001
Location: Finland
Posts: 3,838
muno is on a distinguished road
Send a message via Yahoo to muno
Code:
Dim objFSO
Dim objRegFile
Dim sGivenIP
Dim sGivenModel
Dim QUOTE_CHAR

QUOTE_CHAR = Chr(34)
sGivenModel = InputBox("Model of Desired Printer")
sGivenIP = InputBox("IP of desired Printer")

FOLDER_PATH = "C:\MY\MY PROGRAMS\PRINTER_ADDITION\"
BATCH_FILE = sGivenModel & sGivenIP & ".bat"
REG_FILE = sGivenModel & sGivenIP & ".reg"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objRegFile = objFSO.CreateTextFile(FOLDER_PATH & REG_FILE, True)
Set objBatchFile = objFSO.CreateTextFile(FOLDER_PATH & BATCH_FILE, True)

objRegFile.WriteLine "Windows Registry Editor Version 5.00"
objRegFile.WriteLine " [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_" & sGivenIP & "]"
objRegFile.WriteLine QUOTE_CHAR & "Protocol" & QUOTE_CHAR & "=dword:00000001"
objRegFile.WriteLine QUOTE_CHAR & "Version" & QUOTE_CHAR & "=dword:00000001"
objRegFile.WriteLine QUOTE_CHAR & "Hostname" & QUOTE_CHAR & "=" & QUOTE_CHAR & QUOTE_CHAR
objRegFile.WriteLine QUOTE_CHAR & "HWAddress" & QUOTE_CHAR & "=" & QUOTE_CHAR & QUOTE_CHAR
objRegFile.WriteLine QUOTE_CHAR & "IPAddress" & QUOTE_CHAR & "=" & QUOTE_CHAR & sGivenIP & QUOTE_CHAR
objRegFile.WriteLine QUOTE_CHAR & "PortNumber" & QUOTE_CHAR & "=dword:0000238c"
objRegFile.WriteLine QUOTE_CHAR & "SNMP Community" & QUOTE_CHAR & "=" & QUOTE_CHAR & "public" & QUOTE_CHAR
objRegFile.WriteLine QUOTE_CHAR & "SNMP Enabled" & QUOTE_CHAR & "=dword:00000001"
objRegFile.WriteLine QUOTE_CHAR & "SNMP Index" & QUOTE_CHAR & "=dword:00000001"

objRegFile.Close

objBatchFile.WriteLine "regedit /s " & QUOTE_CHAR & FOLDER_PATH & REG_FILE & QUOTE_CHAR
objBatchFile.WriteLine "net stop spooler"
objBatchFile.WriteLine "net start spooler"
objBatchFile.WriteLine "rundll32 printui.dll,PrintUIEntry /if /b " & QUOTE_CHAR & sGivenModel & QUOTE_CHAR & " /f %windir%\inf\ntprint.inf /r " & QUOTE_CHAR & "IP_" & sGivenIP & QUOTE_CHAR & " /m " & QUOTE_CHAR & sGivenModel & QUOTE_CHAR
objBatchFile.Close
There's the final script, I added few quote_chars where needed.

Thanks again Vass!

//edit:
Whee! I figured out how to create a folder and put the files made by the script to the created folder
WHEE!

Last edited by muno; 03-16-2004 at 05:48 AM.
muno is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 02:06 PM.