LebGeeks

A community for technology geeks in Lebanon.

You are not logged in.

#1 March 21 2016

Stygmata
Banned

windows script

hello
i have a windows 7 application that resides in the system 32 folder ..it works only with admin right .
I have a small setup : active directory and client computers ..i need a small script to make the app run as administrator without putting the password each time

I found this but it is not working :


'This script allows limited accounts to use PrintArtist (PA)
 'as the Administrator. It must be placed in the same
 'folder with the executable program file for PA. A shortcut
 'to this script file can then be put on the student Desktop.
 'Your antivirus program may need to be set to allow scripts.
-------------------------------------------------------------------------------------------
Option explicit
 dim oShell
 set oShell= Wscript.CreateObject("WScript.Shell")
 oShell.Run "runas /user:administrator ""PrintArt.exe"""
 WScript.Sleep 100
 'Replace the string yourpassword~ below with
 'the password used on your system. Include tilde 
 oShell.Sendkeys "yourpassword~"
 Wscript.Quit

I changed the user to runas /user: centralmotors.local\administrator  and changed "yourpassword~" to the password lets say "123456~" 
i saved the vbs inside the executable exe folder but it is not working

Offline

#2 March 21 2016

scorz
Member

Re: windows script

            Process yourApp = new Process();
            yourApp.StartInfo.FileName = @"Path/to/your/app";
            yourApp.StartInfo.UseShellExecute = true;
 yourApp.StartInfo.Verb = "runas";

            System.Security.SecureString passwd = new System.Security.SecureString();
            var __passwd = "yourpasswd";
            foreach(char c in __passwd)
            {
                passwd.AppendChar(c);
            }

            //yourApp.StartInfo.UserName  = "Administrator"; <== Not sure if you need this

            yourApp.StartInfo.Password = passwd;
            yourApp.StartInfo.Domain = "yourdomain";
           
            yourApp.Start();

This is a C# snippet. I am not sure if it's what you need..
PS: didn't test it.

Offline

#3 March 21 2016

rolf
Member

Re: windows script

Stygmata wrote:

I changed the user to runas /user: centralmotors.local\administrator  and changed "yourpassword~" to the password lets say "123456~" 
i saved the vbs inside the executable exe folder but it is not working

To make sure, do you have an app called "PrintArt.exe"? Can you run it by just typing PrintArt on the command prompt?

Online

#4 March 21 2016

Stygmata
Banned

Re: windows script

scorz wrote:
            Process yourApp = new Process();
            yourApp.StartInfo.FileName = @"Path/to/your/app";
            yourApp.StartInfo.UseShellExecute = true;
 yourApp.StartInfo.Verb = "runas";

            System.Security.SecureString passwd = new System.Security.SecureString();
            var __passwd = "yourpasswd";
            foreach(char c in __passwd)
            {
                passwd.AppendChar(c);
            }

            //yourApp.StartInfo.UserName  = "Administrator"; <== Not sure if you need this

            yourApp.StartInfo.Password = passwd;
            yourApp.StartInfo.Domain = "yourdomain";
           
            yourApp.Start();

This is a C# snippet. I am not sure if it's what you need..
PS: didn't test it.

How cani make it into an executable ( something the user to click )

Offline

#5 March 21 2016

Stygmata
Banned

Re: windows script

rolf wrote:
Stygmata wrote:

I changed the user to runas /user: centralmotors.local\administrator  and changed "yourpassword~" to the password lets say "123456~" 
i saved the vbs inside the executable exe folder but it is not working

To make sure, do you have an app called "PrintArt.exe"? Can you run it by just typing PrintArt on the command prompt?

This is an example..let's sayit exists..i can run it by double clicking on it

Offline

#6 March 21 2016

rolf
Member

Re: windows script

Stygmata wrote:
rolf wrote:
Stygmata wrote:

I changed the user to runas /user: centralmotors.local\administrator  and changed "yourpassword~" to the password lets say "123456~" 
i saved the vbs inside the executable exe folder but it is not working

To make sure, do you have an app called "PrintArt.exe"? Can you run it by just typing PrintArt on the command prompt?

This is an example..let's sayit exists..i can run it by double clicking on it

Then when you say it is not working what exactly is happening? That might help in giving a clue, for the experts out there.
I don't know if I should consider myself an expert I've used Wscript and wrote several scripts in VBscript, but that was long time ago.

Stygmata wrote:

How cani make it into an executable ( something the user to click )

In Windows, it's probably just a matter of pasting it in a text file and saving it with the right extension. I don't know what that extension would be for C#.
(In Linux, every file has a special "executable" bit that has to be set, and also the first line of a script can have special meaning to execute the script, like you saw in your perl script - #!/usr/bin/perl)

Last edited by rolf (March 21 2016)

Online

#7 March 22 2016

Stygmata
Banned

Re: windows script

when i run the script i get a cmd windows asking for the password ( which i already set and should not be asked for ) if i type the password and enter nothing happens ..but if i right click on the icon and run as admin ( with inputting the pass ) it works

Offline

#8 March 22 2016

rolf
Member

Re: windows script

Check this maybe:
https://gallery.technet.microsoft.com/s … 87233bc55b
Maybe you need to do a senkeys {ENTER}? Maybe a longer wait before entering the password (sleep 1000 instead of 100)?
Also here:
http://superuser.com/questions/521278/h … thenticate
They mention a "savecred" option for runas, maybe useful for you.

Sorry if useless, just trying to help.

Last edited by rolf (March 22 2016)

Online

#9 March 22 2016

Stygmata
Banned

Re: windows script

rolf wrote:

Check this maybe:
https://gallery.technet.microsoft.com/s … 87233bc55b
Maybe you need to do a senkeys {ENTER}? Maybe a longer wait before entering the password (sleep 1000 instead of 100)?
Also here:
http://superuser.com/questions/521278/h … thenticate
They mention a "savecred" option for runas, maybe useful for you.

Sorry if useless, just trying to help.

thank you rolf .. this sounds promissing : runas /noprofile /user:joe-pc\joe /savecred script.bat
instead of script .bat i should replace it with print.exe correct ?

Offline

#10 March 22 2016

Stygmata
Banned

Re: windows script

i tried the command but i believe there is something missing .. it asks me for the password but nothing opens

Offline

#11 March 22 2016

rolf
Member

Re: windows script

What is the command that you're trying to run with administrator privileges? Try maybe replacing it in your script by the command "dir" and see if you get a folder listing after entering the password, then we can know at least that one part of the script is working. At the moment it's hard to pinpoint which part is not working.

Online

#12 March 22 2016

Stygmata
Banned

Re: windows script

i used exactly this command :  runas /noprofile /user:joe-pc\joe /savecred print.exe    (changed the user of course )
now i have a huge security threat as i was forced to give the user admin rights for the software to work ... it is shitty
the software is called MEDPOS ( something for car parts ) and it is terribly shitty ..even their support doesnt know what to do

PS : local admin doesnt work as well ..only the admin used for installation works .

Offline

#13 March 22 2016

scorz
Member

Re: windows script

I suggest you put your code in a cmd (C# Command prompt Project)
If this snippet works ok. Users will only have to run the cmd exe file(just like a regular software)
Not sure if it works though.

Offline

#14 March 22 2016

rolf
Member

Re: windows script

it does sound like old "legacy" (shitty) software, as it needs admin rights to run. For software that tries to take over your computer or requires an older OS one option is to install them in a virtual machine (like provided by VirtualBox). Of course it will need an OS install wich is an overhead of several gigabytes, which is very inefficient space-wise, but then you can stop worrying about  backwards compatibility (if you upgrade your OS) or security anymore, or not even breaking the software, as you can create snapshots and go back to a previous state. On the other hand networking and sharing files between the host and guest can be painful.

Online

#15 March 22 2016

Stygmata
Banned

Re: windows script

rolf wrote:

it does sound like old "legacy" (shitty) software, as it needs admin rights to run. For software that tries to take over your computer or requires an older OS one option is to install them in a virtual machine (like provided by VirtualBox). Of course it will need an OS install wich is an overhead of several gigabytes, which is very inefficient space-wise, but then you can stop worrying about  backwards compatibility (if you upgrade your OS) or security anymore, or not even breaking the software, as you can create snapshots and go back to a previous state. On the other hand networking and sharing files between the host and guest can be painful.

This what i was thinking to do .. I will install the smallest xp version on a virtualbox ora vm..but teachi g the user is painful and will add to my shadow IT

Offline

#16 March 23 2016

MrClass
Member

Re: windows script

I recall there was a way to emulate an os and run apps in it while having displayed as if its running natively. Its something made by vmware.

So basically running apps in a compatible sandbox without the annoyances of running an extra full os

Any idea anyone?

Offline

#17 March 23 2016

Stygmata
Banned

Re: windows script

MrClass wrote:

I recall there was a way to emulate an os and run apps in it while having displayed as if its running natively. Its something made by vmware.

So basically running apps in a compatible sandbox without the annoyances of running an extra full os

Any idea anyone?

i received an email from the software creator stating the app runs only in admin mode
im currently downloading virtualbox to test it ( im familiar with VM but not VB ) the app only needs internet connection so let's see

Offline

Board footer