Link to home
Start Free TrialLog in
Avatar of sVirgo
sVirgo

asked on

Run SQLConfigDataSource from program as a standard user - Vista

I am running my application as standard user on Vista and SQLConfigDataSource to add system dsn fails.
How can I elevate this command or run as administrator.
int return = SQLConfigDataSource(hwndP, ODBC_ADD_SYS_DSN, "SQL Server",
                                                  "DSN=" + sTargetDSN + '\0' +
                                                  "Description=" + _T("") + '\0' +
                                                  "Server=" + sSQLServer + '\0' +
                                                  "Database=" + sSQLDatabase + '\0' +
                                                  "UID=sa"+'\0'+
                                      "Trusted_Connection=No" + '\0' + '\0');

Thank you!
Avatar of jkr
jkr
Flag of Germany image

Enbed a manifest file demanding that in your executable. See http://msdn.microsoft.com/msdnmag/issues/07/01/UAC/default.aspx?loc=en#S8 ("Marking Required Privileges Using an Application Manifest") and http://msdn.microsoft.com/msdnmag/issues/07/01/UAC/default.aspx?loc=&fig=true#fig6 ("") in particular: The scoop is to

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86"
     name="AdminApp"
     type="win32"/>
  <description>Description of your application</description>
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>

Open in new window

Avatar of sVirgo
sVirgo

ASKER

I already have this manifest file for my application(exe file). However, the code above is a part of dll file which is causing me problem.  And it fails at this SQLConfigDataSource command.  My exe file calls a function of the dll file to create system dsn.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sVirgo

ASKER

I have added manifest with exe file.

No, it does not ask me anything on this command, it just fails.

As a test, I tried to create system DSN manually by going to control panel as a standard user and it refuses and gives message can not create registry entries.

Is that the only mafest or are you isng two? If so, just try to merge the admin thing from the second one to your original manifest.
Avatar of sVirgo

ASKER

This dll is used by other applications also. I am trying to fix piece by piece applications of the project for vista standard user.

I had sqlconnect command which did not work from this dll, so I had to connect with sql server authentication.

Now I am stuck with this command, is there no way to run this command run as admin. Like with Executeshell command or any other way.
Avatar of sVirgo

ASKER

Any more clues to fix it?
This is starting to puzzle me. I wonder why it works in all other cases, just not here...
Oh, wrong button
Avatar of sVirgo

ASKER

Hi jkr,

As an admin user on vista, offcourse it works.

But I am trying to create system DSN with standard user. I am not allowed unless I give admin password. I do not think that in real life the standard user would know the admin password.

So either I have to separate features which can be run by admin only and which can be run by standard user.

So there is no offend to your solution.

Thank you!
Avatar of sVirgo

ASKER

Hi jkr,

May be I did not put question properly.

I was trying to create system DSN as a standard use without giving admin password.

Thank you!