MSFN Forum: some batch file coding help needed... - MSFN Forum

Jump to content



  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

some batch file coding help needed... with a batch code brain teaser... Rate Topic: -----

#21 User is offline   #rootworm 

  • Member
  • PipPip
  • Group: Members
  • Posts: 206
  • Joined: 16-July 06

Posted 20 October 2006 - 11:37 PM

just thought i'd mention that there's an easier way to use FC. you can rely on the errorlevel instead of checking the output for a specific string. it returns an errorlevel of 0 if the files are identical, or 1 if they don't match.


#22 User is offline   soporific 

  • Friend of MSFN
  • PipPipPipPipPip
  • Group: Members
  • Posts: 705
  • Joined: 12-June 05

Posted 23 October 2006 - 06:05 PM

got some more brain teasers... :sneaky:

* when you install hotfixes manually, a lot of the time in Windows 98se you are asked to reboot the computer so the OS will use the new system files. My question is this:

- what exactly is happening when the system needs to reboot to complete an install. ie what tasks are set to complete on reboot, and how are they carried out ... just the abstract of the process, not the nitty gritty.
- can you "stack" up installing hotfixes that would normally ask you to reboot after each one? I know its possible in lots of cases, but I want to know what the restrictions are ... ie if there are 2 hotfixes with different versions of the same file, do they need to be installed separately? Is there a limit to the number of hotfix installs you can "stack up" before rebooting?

* under what circumstances can you install Dial-Up Networking 1.4 on Windows 98 se ?
- it obviously installs onto a clean install of Win98 with no updates yet installed, but ...
- at some stage, you get a message saying "This update was not designed for your version of Windows"
- when does this happen? The only clue I have so far is that it might be when you install the dsclient update that it happens, but that's a wild guess at this stage.

EDIT: well I can't replicate the "This update was not designed for your version of Windows" message, but I did notice that it produced a boot up error (can't find ndiswan.vxd - your system.ini file refers to a file blah blah blah) - but that was possibly my fault - I'm testing again
EDIT2: no bootup error, but it still won't install nicely --- it does on a perfectly clean Win98 installation, but if I try to apply the update after everything else, I get problems ...

- seems liek the easiest thing is to repackage the hotfix, but not sure how to go about doing this with the file in question (Dial-Up Networking 1.4 on Windows 98 se) - any help much appreciated.

* And what's up with the kb892211 Web folders update? The bloomin thing wants to automatically reboot when I don't want it to!! I am using the /Q:A /R:N switch but it obviously doesn't work.

thanks in advance for help --- the honour roll of people I have to thank for helping with the autopatcher is slowly growing ... :)

This post has been edited by soporific: 23 October 2006 - 10:28 PM


#23 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 9,114
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 25 October 2006 - 03:15 AM

soporific said:

- what exactly is happening when the system needs to reboot to complete an install. ie what tasks are set to complete on reboot, and how are they carried out ... just the abstract of the process, not the nitty gritty.


Basically some settings in the Registry must be changed.

You can shave off some reboot time by NOT rebooting but rather terminating the shell (exiting to MS-DOS) and restart it with the command line WIN command.

Moreover, most of the time you don't really need to re-start/re-boot for each install, you can install a number of things and unless one depends on another one a single re-start/re-boot will be enough to update all chnges in one round.

Of course on some install this will not work beacuse in some instances a "real" re-boot is needed.

The install programs can rely on various ways to complete install:
1) Autoexec.bat (in this case a re-boot is mandatory)
2) Wininit.ini
3) Winstart.bat
4) Registry keys, in HKLM or HKCU, typically:
4.1) Runonce
4.2) RunServices
4.3) Runex
5) The StartUp group, or All User Startup

More details here:
http://users.iafrica...rke/startup.htm

#24 User is offline   soporific 

  • Friend of MSFN
  • PipPipPipPipPip
  • Group: Members
  • Posts: 705
  • Joined: 12-June 05

Posted 29 October 2006 - 07:13 PM

View Postjaclaz, on Oct 25 2006, 07:15 PM, said:

Basically some settings in the Registry must be changed. <snip>

Thanks for the info!

Just letting people know: I posted a link to a file version checker a couple of weeks ago on this thread, but it was a big mistake going with it. When using it, it seemed that you couldn't grab the file version number from a VXD file because it wasn't a system library file but a device driver file. But you can. Gape's unoffical service pack uses GETVER which only produces one line of text: the file version, and the name of the file. Much much easier to use for checking purposes. I don't know where to get it without getting the Unofficial sp2 but at least you know its in there.

So, this means all my checking code is going to change!! No more using file dates!! Yay!!

#25 User is offline   Petr 

  • Friend of MSFN
  • PipPipPipPipPip
  • Group: Members
  • Posts: 981
  • Joined: 15-April 05
  • OS:98SE
  • Country: Country Flag

Posted 30 October 2006 - 12:43 AM

View Postsoporific, on Oct 30 2006, 02:13 AM, said:

Gape's unoffical service pack uses GETVER which only produces one line of text: the file version, and the name of the file. Much much easier to use for checking purposes. I don't know where to get it without getting the Unofficial sp2 but at least you know its in there.


You can get it here: http://thunder.proho...d32.html#getver

Other utility is Microsoft's FILEVER, it provides a bit more details including language version.

Petr

#26 User is offline   oscardog 

  • Member
  • PipPip
  • Group: Members
  • Posts: 234
  • Joined: 29-June 06

Posted 30 October 2006 - 05:07 AM

View PostPetr, on Oct 30 2006, 06:43 AM, said:

View Postsoporific, on Oct 30 2006, 02:13 AM, said:

Gape's unoffical service pack uses GETVER which only produces one line of text: the file version, and the name of the file. Much much easier to use for checking purposes. I don't know where to get it without getting the Unofficial sp2 but at least you know its in there.


You can get it here: http://thunder.proho...d32.html#getver

Other utility is Microsoft's FILEVER, it provides a bit more details including language version.

Petr

I seen to get filetype not allowed from the server, http://lbrisar.htmlp...om/e_cmd32.html seems to download,scan and work ok. Thanks for the heads up Petr

#27 User is offline   soporific 

  • Friend of MSFN
  • PipPipPipPipPip
  • Group: Members
  • Posts: 705
  • Joined: 12-June 05

Posted 02 November 2006 - 06:43 PM

oohh got a good one...

consider the following code:

@echo off
:: tests for the location of the windows directory
:: this code works as expected.
IF %windir%==C:\Windows goto END
Echo. the windows directory is not in the default location.
PAUSE
CLS
EXIT

:End
Echo. the windows directory is in the default location.
PAUSE
EXIT

and ...

@echo off
:: write the letter 'Y' to a file called MyFile.txt
:: this code works as expected.
Echo Y> "C:\MyFile.txt"
EXIT


My question is this: for people that understand batch file programming, what would you expect the following code to do? (n.b - It is example code, it has no relation to any of my projects!) --- see if you can work it out without actually trying out the code for real --- and then test it. Or just test it anyway to see the result if you have no idea!

:: this code is designed to test that
:: 2 directory locations match up
:: write Y to a file if they do match
::
<snipped>  it was a red herring!!!

@echo off
SET mydir=C:\notexist
IF EXIST "C:\MyFile.txt" DEL "C:\MyFile.txt"
IF %mydir%==C:\exist Echo Y> "C:\MyFile.txt"
IF EXIST "C:\MyFile.txt" goto END
Echo. the directories do not match up
PAUSE
CLS
EXIT

:End
Echo. the directories do match up
PAUSE
EXIT


So, who can guess what happens? And don't just guess, tell us why you think your guess is correct!! And no cheating!! :P

Of all the bugs I've had trouble digging out, the one caused by the above code was the most amazing when I realised why it was happening, because IMHO it was so easy to make the mistake. I've had code that had this bug that I just gave up trying to work out why it wasn't working, and just tunnelled around it. So I thought it may be good to see if I'm the only one or if this is a common misconception.

This post has been edited by soporific: 04 November 2006 - 09:02 PM


#28 User is offline   oscardog 

  • Member
  • PipPip
  • Group: Members
  • Posts: 234
  • Joined: 29-June 06

Posted 03 November 2006 - 06:01 AM

Easy mistake to do when if == (strings) and not error levels.
IF (pardon the pun) of any use
IF NOT EXIST C:\exist\nul.ext GOTO End
IF NOT EXIST C:\notexist\nul.ext GOTO End
Echo. the directories do match up
PAUSE
CLS
EXIT

:End
Echo. the directories do not match up
PAUSE
EXIT

#29 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 9,114
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 03 November 2006 - 07:44 AM

And before anyone says:

Quote

Hah! Checking for file C:\exist\nul
would be enough.


Here is the reason why it is better to use nul.ext:
http://xset.tripod.com/tip5.htm

;)

jaclaz

#30 User is offline   soporific 

  • Friend of MSFN
  • PipPipPipPipPip
  • Group: Members
  • Posts: 705
  • Joined: 12-June 05

Posted 04 November 2006 - 09:01 PM

View Postoscardog, on Nov 3 2006, 10:01 PM, said:

Easy mistake to do when if == (strings) and not error levels.


Sorry, i wasn't clear enough. The example code is ONLY to expose the bug. My point is that there is (always) a temptation to try to save extra lines of code than necessary ... ie to be elegant

(method1)
IF [logical test] then [do something]
:Continue

(method2)
IF [logical test] then goto [somewhere]
goto CONTINUE

:[somewhere]
[do something]

:Continue


You would ALWAYS want to use the first method because its less code and less directional label parsing. So you CAN use method1 in all cases EXCEPT when [do something] involves writing to a file - then the bug appears. So, my point is that as it wasn't immediately obvious you couldn't write to a text file as a result of a IF logical test - i was wondering if this had happened to any others ...

I admit to adding a red herring when I wrote:

:: if for some unlikely reason "C:\notexist" or "C:\exist" already exist on your test system
:: change this to something else, and then change the code appropriately

but that was from an earlier version of the test that I forgot to delete (it was only comment anyway) but it did serve to confuse you about the point i was trying to make. Now things should be clear ...

Share this topic:


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy