Page 1 of 2 12>
Topic Options
#190408 - 2008-10-30 06:50 PM Calling a .bat/.exe during logon
markdavies1978 Offline
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
#190409 - 2008-10-30 07:46 PM Re: Calling a .bat/.exe during logon [Re: markdavies1978]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Simply put - yes -

Look at the manual for the command "RUN"
_________________________
Today is the tomorrow you worried about yesterday.

Top
#190410 - 2008-10-30 08:12 PM Re: Calling a .bat/.exe during logon [Re: Gargoyle]
markdavies1978 Offline
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
#190411 - 2008-10-30 08:19 PM Re: Calling a .bat/.exe during logon [Re: markdavies1978]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
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.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#190412 - 2008-10-30 08:27 PM Re: Calling a .bat/.exe during logon [Re: Gargoyle]
markdavies1978 Offline
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 Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
Something like this?

 Code:
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
#190420 - 2008-10-30 10:14 PM Re: Calling a .bat/.exe during logon [Re: eriqjaffe]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
unless you are running wkix32.exe
it shouldn't be able to "spawn"...
_________________________
!

download KiXnet

Top
#190429 - 2008-10-31 11:18 AM Re: Calling a .bat/.exe during logon [Re: Lonkero]
BradV Offline
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
#190430 - 2008-10-31 11:23 AM Re: Calling a .bat/.exe during logon [Re: BradV]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yep.
looks like simple registry write.
_________________________
!

download KiXnet

Top
#190436 - 2008-10-31 04:07 PM Re: Calling a .bat/.exe during logon [Re: Lonkero]
markdavies1978 Offline
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
#190437 - 2008-10-31 04:16 PM Re: Calling a .bat/.exe during logon [Re: markdavies1978]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#190438 - 2008-10-31 04:24 PM Re: Calling a .bat/.exe during logon [Re: Mart]
markdavies1978 Offline
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
#190439 - 2008-10-31 04:28 PM Re: Calling a .bat/.exe during logon [Re: markdavies1978]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#190440 - 2008-10-31 04:42 PM Re: Calling a .bat/.exe during logon [Re: Mart]
markdavies1978 Offline
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 Offline
Fresh Scripter

Registered: 2008-10-30
Posts: 17
Oh, it works fine if I run it manually just not via the logon script...
Top
#190443 - 2008-10-31 04:46 PM Re: Calling a .bat/.exe during logon [Re: markdavies1978]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
What is in the VBS script, we can probably convert it to KiX and there would be no need to Run / Call anything then.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#190444 - 2008-10-31 04:52 PM Re: Calling a .bat/.exe during logon [Re: Gargoyle]
markdavies1978 Offline
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
#190445 - 2008-10-31 04:57 PM Re: Calling a .bat/.exe during logon [Re: markdavies1978]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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

- Chuck Norris once sold ebay to ebay on ebay.

Top
#190446 - 2008-10-31 05:03 PM Re: Calling a .bat/.exe during logon [Re: Mart]
markdavies1978 Offline
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
#190447 - 2008-10-31 05:19 PM Re: Calling a .bat/.exe during logon [Re: markdavies1978]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
What is the content of test.bat?
Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
2 registered (morganw, mole) and 414 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.076 seconds in which 0.025 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org