Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to run bat file as administrator

Status
Not open for further replies.

AlastairP

Technical User
Feb 8, 2011
286
AU
I am trying to create a WIFI hotspot from within my app.
I would like for the users do not have to worry about setting and configuring each time they use the app

I have the commands that create this but these must be "run as administrator" to work (Has been tested - works OK)
I tried the RUN() command as well as a BAT file, the commands ran but did not create the network connection.

I would like this to just run without the user having to right click a bat file to "run as administrator" - just click a command button or even better just executes when the app starts.

The option to tick in properties to "run as administrator" in the BAT file is greyed out
I would prefer to just run all this from the VFP app, no BAT file at all.

Does anyone know how to make this work?



 
That's more complicated than RUN. You would need to use CreateProcessAsUser. It's not neccessarily working, users will at least need the privilege to run elevated processes. It would be better to once configure a permanent wifi hotspot. REad more about it here:
Bye, Olaf.
 
Perhaps this will help (Not tested in Windows 8)

Code:
Public Array aconnections[1]
aconnections[1]=''
LOCAL singleconnection
 i = 1
 o = Createobject("Shell.Application")
 ns=o.NameSpace (3)
For Each oItems In  ns.Items
   If oItems.Name ="Network Connections"  && Windows Anglais
     colNetwork = oItems.getfolder
     If Vartype(colNetwork) = "O"
       For Each colConn In colNetwork.Items
         If Alen(aconnections)= 1 And Empty(aconnections[1])
         Else
           Dimension aconnections[ALEN(aconnections)+1]
         Endif
         aconnections[i]=colConn.Name
         i = i +1
       Next
     Endif
   Endif
Next
For i = 1 To Alen(aconnections)
   If "Titan" $ aconnections[i]  &&Un example
     Connect(aconnections[i])
   Endif
Next
Function Connect(lcConnexion)
For Each colConn In colNetwork.Items
   If colConn.Name = lcConnexion
     singleconnection = colConn
     Exit
   Endif
Next
For Each clsVerb In singleconnection.Verbs
     If "C&onnect" = clsVerb.Name Or "En&able" = clsVerb.Name
       Try
         singleconnection.InvokeVerb("C&onnect")
       Catch
         singleconnection.InvokeVerb("En&able")
       ENDTRY
     Endif
   Next
Endfunc

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Thanks Mike, Olaf
I will work on these suggestions

Regards

Alastair
 
Hi Mike,

The namespace (3) does not refer to the location of my network connections - I am using Win 7

Control Panel\Network and Internet\Network Connections

How do I find out what the namespace reference is to specific system locations?
(Totally new to using this)

 
No the namespace(3) refers to all items in the control panel.

Code:
clear 
o = Createobject("Shell.Application")
ns=o.NameSpace (3)
For Each oItem In ns.items
	? oItem.name
endfor


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
But I don't this this works in win7 x64

Result of namespace(3):

Code:
Java
Mail
Program Updates
Flash Player
Adobe Gamma

Win7 control panel there is no item for "Network Connections"
Network connections is branched off "Control Panel\Network and Internet\Network Connections"
 
Sorry,

MSDN is your ource of information about Microsoft Windows

is telling us, you need a ShellSpecialFolderConstant for the parameter of the Namespace method. And these constants are described at ,which defines ssfNETWORK = 0x12 as the constant for the Network node.

So replace 3 with 0x12 = 18
Code:
clear 
o = Createobject("Shell.Application")
ns=o.NameSpace(18)
For Each oItem In ns.items
	? oItem.name
endfor

Bye, Olaf.
 
Thanks Olaf

That's just what I need, thanks for pointing me in the right direction

Regards

Alastair
 
Olaf
If I us namespace(3) in windows 7 32 bit, I get a list of all item in the control panel.
Power Options
Notification Area Icons
Taskbar and Start Menu
Credential Manager
Default Programs
RemoteApp and Desktop Connections
Windows Update
Desktop Gadgets
Windows Firewall
Phone and Modem
Java
Speech Recognition
Windows Mobility Center
User Accounts
Region and Language
HomeGroup
Mouse
Folder Options
Keyboard
Device Manager
Windows CardSpace
Performance Information and Tools
Programs and Features
Indexing Options
Network and Sharing Center...

But using namespace(18) does get me close to network sharing panel, but does not permit to active a wireless connection from there.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Well, the topic changed, Mike Lewis was suggesting using Shell.Application.
18 is listing networks, maybe that's all Alastair needs.

Here On Win7 for 3 I only get:
Java, E-Mail, Flash Player
At home about the same, not anywhere near Network and Sharing Center.

To create a new WLAN on the fly I think is out of the scope of using Shell.Application. I don't know what you would best use, perhapos netsh:
Bye, Olaf.
 
Namespace (49) gets me to the network connections in win7 x64
 
OK, we can all contribute what we get with what parameter. 49 in hexadecimal is 31, which is not defined in
I'm at home now, and like in the office, have a win7 64 bit OS.

Via Namespace(3) I get "Java", "Quicktime" and "Flash Player", but far from all nodes.
Via Namespace(18) I get names of Network devices
Via Namespace(49) I get names of LAN Connections

I don't see 3 and 49 documented, but meybe there is some more thorough documentation somewhere else in the depths of the MSDN even Google wasn't bold enough to dive into.

Take whatever helps you, but it seems the results of the namespace method are not consistent through all OSes and computers.

Bye, Olaf.
 
Yes, google was not my friend with this one.
I will work on this issue and see what eventuates

Alastair
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top