|
|
|||||||
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. |
||||||||
|
|
|||||||
Simply put - yes - Look at the manual for the command "RUN" |
||||||||
|
|
|||||||
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? |
||||||||
|
|
|||||||
What is in your batch file. If it is just calling another executable, run the executable and do away with the batch file. As to running silently, it depends on what you are doing and if the application that you are running supports it. Many factors can come into play, but need more information to give advice. |
||||||||
|
|
|||||||
It is a script to add a SQL DSN to certain PC's. |
||||||||
|
|
|||||||
Something like this? Code: RUN ("%COMSPEC% /C START /MIN batchfile.bat") That should spawn your batch file in another minimized window. |
||||||||
|
|
|||||||
unless you are running wkix32.exe it shouldn't be able to "spawn"... |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
yep. looks like simple registry write. |
||||||||
|
|
|||||||
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? |
||||||||
|
|
|||||||
My guess would be yes if the person has an L drive mapped before starting the batch file and he/she has access to the drive and it's folders. |
||||||||
|
|
|||||||
Doesn't seem to work with the above or if I use the full UNC path... |
||||||||
|
|
|||||||
If you put some de bug lines in the batch file (echo to the screen, pauses and stuff) do you see those lines so you know it is running? What does the batch file do? Can you post its contents? |
||||||||
|
|
|||||||
The bat file contains the following: cscript \\servername\path\odbc_ini.vbs |
||||||||
|
|
|||||||
Oh, it works fine if I run it manually just not via the logon script... |
||||||||
|
|
|||||||
What is in the VBS script, we can probably convert it to KiX and there would be no need to Run / Call anything then. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
Looks like it is just writing stuff to ini files. Not 100% sure because I'm almost blind in the VBS world. Kix can write to ini files for you so you don't need the VBS script anymore. One other thing, you are writing to win.ini and odbc.ini in the %windir%. Regular users cannot write to those file with default permissions set on the files and folders. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
What is the content of test.bat? |
||||||||
|
|
|||||||
Try adding this to your KiX script and test it. Code: $WinIni = %windir%+"\win.ini" $ODBCIni = %windir%+"\odbc.ini" $RC = WriteProfileString($WinIni,"db9server","Driver","C:\WINNT\SYSTEM\sqlsrvr.dll") $RC = WriteProfileString($WinIni,"db9server","Description","") $RC = WriteProfileString($WinIni,"db9server","Server","db9server") $RC = WriteProfileString($WinIni,"db9server","Address","172.27.44.54,1443") $RC = WriteProfileString($WinIni,"db9server","UseProcForPrepare","Yes") $RC = WriteProfileString($WinIni,"db9server","QuotedId","Yes") $RC = WriteProfileString($WinIni,"db9server","AnsiNPW","Yes") $RC = WriteProfileString($WinIni,"db9server","OemtoAnsi","No") $RC = WriteProfileString($WinIni,"db9server","Trusted_Connection","") $RC = WriteProfileString($ODBCIni,"ODBC Data Sources","db9server","SQL Server") |
||||||||
|
|
|||||||
Originally Posted By: BradV What is the content of test.bat? cscript odbc_ini.vbs |
||||||||
|
|
|||||||
Originally Posted By: Gargoyle Try adding this to your KiX script and test it. Code: $WinIni = %windir%+"\win.ini" $ODBCIni = %windir%+"\odbc.ini" $RC = WriteProfileString($WinIni,"db9server","Driver","C:\WINNT\SYSTEM\sqlsrvr.dll") $RC = WriteProfileString($WinIni,"db9server","Description","") $RC = WriteProfileString($WinIni,"db9server","Server","db9server") $RC = WriteProfileString($WinIni,"db9server","Address","172.27.44.54,1443") $RC = WriteProfileString($WinIni,"db9server","UseProcForPrepare","Yes") $RC = WriteProfileString($WinIni,"db9server","QuotedId","Yes") $RC = WriteProfileString($WinIni,"db9server","AnsiNPW","Yes") $RC = WriteProfileString($WinIni,"db9server","OemtoAnsi","No") $RC = WriteProfileString($WinIni,"db9server","Trusted_Connection","") $RC = WriteProfileString($ODBCIni,"ODBC Data Sources","db9server","SQL Server") How can I run this for specific users only? |
||||||||
|
|
|||||||
In this part of your script Code: IF INGROUP ("ODBC_UPDATE") RUN "L:\Policy_Area\TEST.bat" ENDIF Replace your run statement with the above code |
||||||||
|
|
|||||||
Thanks Gargoyle, getting there! It has now addedd the required ODBC entry apart from the IP address! |
||||||||
|
|
|||||||
Glad to help. There are ways to make the code cleaner and faster if you ever want to explore those options, but that is your call. And welcome to the world of KiX. |
||||||||
|
|
|||||||
I'm still stuggling to get the IP address added to the ODBC setting. It adds the SQL entry & server name fine which is great just not the Network Address... I think the code from the previous posts isn't adding the address to C:\Windows\win.ini & C:\Windows\ODBC.ini |
||||||||
|
|
|||||||
This is the line that is not working ? $RC = WriteProfileString($WinIni,"db9server","Address","172.27.44.54,1443") Add this line directly after it and see what the error code is Code: "Return code was "+@Error+" "+@SError ? |
||||||||
|
|
|||||||
Gargoyle, Having had a chat with 1 of my developers I simply had to adjust the example code you posted. Thanks. |
||||||||
|
|
|||||||
why use the .bat file, when you can just shell the same line with kix? if you still want to keep on using that vbs-script, that is... |