determining if user has shell access

Monte Goulding monte at sweattechnologies.com
Fri Oct 15 01:57:14 EDT 2010


> I'm assuming that at this point you don't know if this is some policy setting or simply the removal of some file.

It's a policy setting. Everything works fine if they run as an admin user. 

Aha! Google is my friend ;-)

By checking the registry key: HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\DisableCMD"=dword:1 we can find out if cmd.exe is disabled for the current user. 

Apparently command.com is often available when cmd isn't but unfortunately if I set the shellCommand to command.com it returns nothing (in vista). If I use command.com on the command line it works fine so I'm assuming the problem is on the LiveCode side of things. It would be good if a few others tested this so we can report it if it's not just my system.

function safeShell pCommand
   -- assume the shellCommand has been set appropriately
   set the hideConsoleWindows to true
   set the itemDel to "\"
   if item -1 of the shellCommand is "cmd.exe" AND \ 
          charToNum(queryRegistry("HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\DisableCMD")) = 1 then
      -- don't use cmd.exe because shell() won't return
      -- don't revert to command.com because there seems to be a problem in the engine
      return executeProcess(pCommand)
   else
      try
         -- still check for empty if your are expecting a result
         -- because there's no execution error on os x
         return shell(pCommand)
      catch e
         -- execution error on windows shellCommand doesn't exist
	 -- hopefully this catches hash rule blocks
         return "Error executing command"
      end try
   end if
end safeShell


function executeProcess pProcess,pElevate
   local tReturn
   if pElevate then
      open elevated process pProcess for text read
   else
      open process pProcess for text read
   end if
   repeat forever
      # Loop until there are no more lines to read.
      read from process pProcess for 1 line
      if the result = "" or the result = "timed out" then
         -- something to add
         put it after tReturn
      else
         close process pProcess
         return tReturn
      end if
   end repeat
end executeProcess

Cheers

--
Monte Goulding
M E R Goulding Software Development
Bespoke application development for vertical markets

InstallGadget - How to create an installer in 10 seconds
revObjective  - Making behavior scripts behave




More information about the use-livecode mailing list