Thursday, September 12, 2013

How Do You Write a Program Install Script in Windows 7?

Sometimes when you ask a simple question, you don't get a simple answer.  (I understand, however, if you ask a stupid question, the expected concord tends to occur.)  And you start to believe it's because there isn't an easy answer.  I wanted to know how to request admin rights in an install script running on Windows 7 so that a user could approve the request for admin privilege to install a program.  (I'm only dealing with the situation where the user has admin privilege to pass on to my program.)

Lots of people have had this question and answers abound.  Generally, I find that there are at least three categories of responses to questions that are a little off the beaten path:
  1. You can't/shouldn't do that! (Meaning, I think, sometimes, that they envy the questioner for thinking to ask the question and don't want a good answer to exist:  "That's stupid, so there!")
  2. Here's an awesome (or complicated) strategy for doing it!
  3. Um, I don't know if this is exactly what you want, but it might do what you need.  Depending on your situation, maybe it's good enough?
Regarding my latest problem, people say, "That would be a major security issue!" (Not so.  An install script is only logical where the requirement is that the user trusts the script.  Otherwise, why exactly is the user installing the program? Um, duh?)  Plenty of category 1) out there.  And in the same online forums, there are a few category 2) responses out there.  And "hats off" to them.  But I'm here to give you a category 3) response.

Create two files.  The first one is just a stub that requests the admin privileges for the second script.  The second script does all of the work.  Here is the first script:



Call the script (containing the above code) setup.js or some other suitable name.  Now, you go decide what your second script needs to do—the one named subsetup.js (or whatever you decide to call it).

A caveat needs to be mentioned—although the above scheme worked on my home machine, on another computer the "runas" operation did not trigger an administrator privilege request.  It could be related to policy restrictions.
Post a Comment