Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

modifying cmd file on user machine


4 replies to this topic

Mariscal

Mariscal
  • Full Members
  • 50 posts

Posted 15 August 2008 - 19:05

Hello All,

I'm trying to modify a cmd file included with my installation so that it has the TARGETDIR chosen by the user written to it after OnFirstUIBefore. The last entry in the cmd file before it gets written to looks like this:

call "<insert drive letter>:\program files\Company Name\App\App.cmd"

So what I want to do is simply replace what's in the double quotes with the actual drive letter and TARGETDIR.

This seemed straightforward enough: I opened the file in Binary mode, used SeekBytes with FILE_BIN_END to position the pointer (since this is the last call in the file), and then used WriteBytes to write the actual install path into the file.

The problem is if there are characters remaining from the original call statement shown above: I don't know how to guarantee that this will be completely overwritten while allowing subsequent calls to SeekBytes to remain successful. (An example is if E:\App is chosen as the installation path. "E:\App\App.cmdletter>:\program files\Company Name\App\App.cmd" would thus show up in the cmd file.)

Maybe there's a better way, or maybe Installscript doesn't provide a good way to do it at all. Any feedback would be most welcome!

Stefan Krueger

Stefan Krueger

    InstallSite.org

  • Administrators
  • 13,269 posts

Posted 17 August 2008 - 20:06

Why don't you leave that line out of the file (so you don't have to overwrite it), and use the WriteLine function to append the line with TARGETDIR?

Mariscal

Mariscal
  • Full Members
  • 50 posts

Posted 18 August 2008 - 22:15

Thanks, Stefan. I would definitely go for that option, but I'm trying to account for users who have already installed this cmd script with previous releases. I'll likely just have to leave it to the user to configure.

Taco Bell

Taco Bell

    IS6 Expert

  • Moderators
  • 1,281 posts

Posted 19 August 2008 - 14:39

From what you told us, I don't see why you couldn't just re-deploy the CMD file to those previous installations in order to work from a known starting point.

However, if that's not possible, then you just need to alter you original approach to open the file normally (i.e. non-binary) and process each line of text accordingly.

Specifically, you could rename the original file, read a line, and if it doesn't contain this call statement, then write it back out to the expected filename. Continue doing that until you you find the call statement and, in that case, you would write back out the customized command.

Hope it helps.
user posted image

Mariscal

Mariscal
  • Full Members
  • 50 posts

Posted 23 August 2008 - 00:59

Hello, and thank you for the suggestion, I now have a process that works. smile.gif

I treated the file as simple .txt, and this made all the difference.

Thanks again!