#190408 - 2008-10-30 06:50 PM
Calling a .bat/.exe during logon
|
markdavies1978
Fresh Scripter
Registered: 2008-10-30
Posts: 17
|
Hi all,
I'm a novice user of Kix - Only use it to map drives, printers etc.
What I would like to be able to do is during my logon script is to run a bat or exe file in the background/at the same time of logon.
Is this possible?
Thanks.
|
Top
|
|
|
|
#190410 - 2008-10-30 08:12 PM
Re: Calling a .bat/.exe during logon
[Re: Gargoyle]
|
markdavies1978
Fresh Scripter
Registered: 2008-10-30
Posts: 17
|
Ok, got my bat file to run but it's running within the login script window.
Anyway I can get this to run either silently or in it's own window?
|
Top
|
|
|
|
#190412 - 2008-10-30 08:27 PM
Re: Calling a .bat/.exe during logon
[Re: Gargoyle]
|
markdavies1978
Fresh Scripter
Registered: 2008-10-30
Posts: 17
|
It is a script to add a SQL DSN to certain PC's.
|
Top
|
|
|
|
#190413 - 2008-10-30 08:51 PM
Re: Calling a .bat/.exe during logon
[Re: markdavies1978]
|
eriqjaffe
Hey THIS is FUN
Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
|
Something like this?
RUN ("%COMSPEC% /C START /MIN batchfile.bat") That should spawn your batch file in another minimized window.
Edited by eriqjaffe (2008-10-30 08:53 PM)
|
Top
|
|
|
|
#190429 - 2008-10-31 11:18 AM
Re: Calling a .bat/.exe during logon
[Re: Lonkero]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
You can probably do it directly from kix. Here is a link to a script to do it in basic.
http://support.microsoft.com/kb/q184608/
This is using a gui. You could use kixforms, or since you know the data for the DSN, you could just pass it to it (maybe put it in a ini file so that the code is generic).
Regards,
Brad
|
Top
|
|
|
|
#190436 - 2008-10-31 04:07 PM
Re: Calling a .bat/.exe during logon
[Re: Lonkero]
|
markdavies1978
Fresh Scripter
Registered: 2008-10-30
Posts: 17
|
Running the bat file isn't working for me, here it is:
IF INGROUP ("ODBC_UPDATE") RUN "L:\Policy_Area\TEST.bat" ENDIF
Should this work?
|
Top
|
|
|
|
#190438 - 2008-10-31 04:24 PM
Re: Calling a .bat/.exe during logon
[Re: Mart]
|
markdavies1978
Fresh Scripter
Registered: 2008-10-30
Posts: 17
|
Doesn't seem to work with the above or if I use the full UNC path...
|
Top
|
|
|
|
#190440 - 2008-10-31 04:42 PM
Re: Calling a .bat/.exe during logon
[Re: Mart]
|
markdavies1978
Fresh Scripter
Registered: 2008-10-30
Posts: 17
|
The bat file contains the following:
cscript \\servername\path\odbc_ini.vbs
|
Top
|
|
|
|
#190442 - 2008-10-31 04:45 PM
Re: Calling a .bat/.exe during logon
[Re: markdavies1978]
|
markdavies1978
Fresh Scripter
Registered: 2008-10-30
Posts: 17
|
Oh, it works fine if I run it manually just not via the logon script...
|
Top
|
|
|
|
#190444 - 2008-10-31 04:52 PM
Re: Calling a .bat/.exe during logon
[Re: Gargoyle]
|
markdavies1978
Fresh Scripter
Registered: 2008-10-30
Posts: 17
|
Content of VBS script:
' ' 16-bit ODBC setup to run >cscript odbc_ini.vbs ' ' ' Required entries in ODBC.ini - WIN.INI for db9server entry ' ' [ODBC Data Sources] ' db9server=SQL Server ' ' [db9server] ' Driver=C:\WINNT\SYSTEM\sqlsrvr.dll ' Description= ' Server=db9server ' Address=172.27.44.54,1443 ' UseProcForPrepare=Yes ' QuotedId=Yes ' AnsiNPW=Yes ' OemToAnsi=No ' Trusted_Connection=
Const ForReading = 1 Const ForWriting = 2 found="N"
Set Shell = WScript.CreateObject("WScript.Shell")
windowsdir = shell.ExpandEnvironmentStrings("%windir%")
' ------------------------------------------------------------ ' Add entry to WIN.INI ' ------------------------------------------------------------
Set objFSO = CreateObject("Scripting.FileSystemObject") ' Create Backup objFSO.CopyFile windowsdir & "\win.ini",windowsdir & "\win.bak",true WScript.Echo " ...Creating backup " & windowsdir & "\win.bak"
Set objTextFile = objFSO.OpenTextFile(windowsdir & "\win.ini", ForReading) WScript.Echo " ...Updating " & windowsdir & "\win.ini"
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
intLineFinder = InStr(strNextLine, "[SQLSERVER]") If intLineFinder <> 0 Then
strNewFile = strNewFile & strNextLine & vbCrLf strNextLine = objTextFile.Readline
Do Until InStr(strNextLine, "[") <> 0 if InStr(strNextLine, "db9server=") <> 0 then found="Y" WScript.Echo " ...WIN.INI Entry found!!" End If strNewFile = strNewFile & strNextLine & vbCrLf strNextLine = objTextFile.Readline Loop
If found="N" then strNewFile = strNewFile & "db9server=DBMSSOC3,172.27.44.54,1443" & vbCrLf WScript.Echo " ...Adding to Data Sources" End If End If
strNewFile = strNewFile & strNextLine & vbCrLf Loop
objTextFile.Close
If found="N" then WScript.Echo " ...Saving File" Set objTextFile = objFSO.OpenTextFile(windowsdir & "\WIN.ini", ForWriting) objTextFile.WriteLine strNewFile objTextFile.Close End If
' -------------------------------------------------------------- ' Add entries to ODBC.ini ' --------------------------------------------------------------
found="N" strNewFile=""
Set objFSO = CreateObject("Scripting.FileSystemObject") ' Create Backup objFSO.CopyFile windowsdir & "\ODBC.ini",windowsdir & "\ODBC.bak",true WScript.Echo " ...Creating backup " & windowsdir & "\ODBC.bak"
Set objTextFile = objFSO.OpenTextFile(windowsdir & "\ODBC.ini", ForReading) WScript.Echo " ...Updating " & windowsdir & "\ODBC.ini"
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
intLineFinder = InStr(strNextLine, "[ODBC Data Sources]") If intLineFinder <> 0 Then
strNewFile = strNewFile & strNextLine & vbCrLf strNextLine = objTextFile.Readline
Do Until InStr(strNextLine, "[") <> 0 if InStr(strNextLine, "db9server=") <> 0 then found="Y" WScript.Echo " ...ODBC Entry found!!" End If strNewFile = strNewFile & strNextLine & vbCrLf strNextLine = objTextFile.Readline Loop
If found="N" then strNewFile = strNewFile & "db9server=SQL Server" & vbCrLf WScript.Echo " ...Adding to Data Sources" End If End If
strNewFile = strNewFile & strNextLine & vbCrLf Loop
If found="N" then strNewFile = strNewFile & "[db9server]" & vbCrlf strNewFile = strNewFile & "Driver=" & windowsdir & "\SYSTEM\sqlsrvr.dll" & vbCrlf strNewFile = strNewFile & "Description=db9server" & vbCrlf strNewFile = strNewFile & "Server=db9server" & vbCrlf strNewFile = strNewFile & "Address=172.27.44.54,1443" & vbCrlf strNewFile = strNewFile & "UseProcForPrepare=Yes" & vbCrlf strNewFile = strNewFile & "QuotedId=Yes" & vbCrlf strNewFile = strNewFile & "AnsiNPW=Yes" & vbCrlf strNewFile = strNewFile & "OemToAnsi=No" & vbCrlf strNewFile = strNewFile & "Trusted_Connection=" & vbCrlf strNewFile = strNewFile & "LastUser=" & vbCrlf WScript.Echo " ...Adding Entry" End If
objTextFile.Close
If found="N" then WScript.Echo " ...Saving File" Set objTextFile = objFSO.OpenTextFile(windowsdir & "\ODBC.ini", ForWriting) objTextFile.WriteLine strNewFile objTextFile.Close End If
|
Top
|
|
|
|
#190446 - 2008-10-31 05:03 PM
Re: Calling a .bat/.exe during logon
[Re: Mart]
|
markdavies1978
Fresh Scripter
Registered: 2008-10-30
Posts: 17
|
Mart, thanks for your time on this.
I've allowed users to write to these files & tested this by running the vbs file or running my bat file manually.
It just appears to be getting this to run within KIX is my problem
Cheers.
Edited by markdavies1978 (2008-10-31 05:11 PM)
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 515 anonymous users online.
|
|
|