Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8637371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:27:51+00:00 2026-06-12T10:27:51+00:00

I am using an older version of SQL Server (2000). I do not want

  • 0

I am using an older version of SQL Server (2000). I do not want my users to have permission to run master.dbo.xp_cmdshell. I am trying to create a custom DLL that I can use to create my own extended stored procedure that I grant users permission to run – one that is hard-coded to execute a specific batch file that users need to be able to run on demand.

I’m using Visual Studio 2010 to create the DLL. Here is my header file stdafx.h:

#define WIN32_LEAN_AND_MEAN 

#include <windows.h>
#include <iostream>

#ifndef INDLL_H
    #define INDLL_H

    #ifdef EXPORTING_DLL
        extern __declspec(dllexport) void HelloWorld() ;
    #else
        extern __declspec(dllimport) void HelloWorld() ;
    #endif
#endif

and here is my main file dllmain.cpp:

#include "stdafx.h"
#define EXPORTING_DLL

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                   LPVOID lpReserved)
{ return TRUE; }

void HelloWorld() {
    system("f:\\bin\\batchfilename.bat");
}

When I try to debug this project, I see that the build succeeds, but I get an error “Unable to start program: <path to compiled dll>.” Do you think this DLL will work, and if so, how can I test it to see for myself if it works?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:27:52+00:00Added an answer on June 12, 2026 at 10:27 am

    OK, After many hours of Googling, I successfully compiled a DLL to add as a SQL Server 2000 extended stored procedure. I’m going to share it here, since it’s just a compilation of things I’ve put together from my Googling. (I used Visual Studio 2010). I’m not going to post everything – I started by creating a new project in Visual Studio and choosing Win32 Console Application, then Next, then DLL. It creates a few header files and other files for you. Some of them I didn’t see any need for. And some of the header files you must add to the project manually. But here’s my main .cpp code:

    #include "stdafx.h"         
    #include "srv.h"   //Must get from C:\Program Files (x86)\Microsoft SQL Server\80\Tools\DevTools\Include            
    #include "shellapi.h"  //need for ShellExecute          
    #include "string"   //needed for std:string         
    #include <sys/stat.h>  //need for stat in fileExists function below         
    
    #define DLL_FUNC extern "C" __declspec (dllexport)          
    
    __declspec(dllexport) ULONG __GetXpVersion() {          
       return ODS_VERSION;          
    }           
    
    bool fileExists(const std::string& filename) {          
        struct stat buf;            
        if (stat(filename.c_str(), &buf) != -1)         
        { return true; }            
        return false;           
    }           
    
    DLL_FUNC int __stdcall RunPP() {            
        if (fileExists("C:\\FileOnServer\\execute.bat")) {      
            ShellExecute(NULL,TEXT("open"), TEXT("C:\\FileOnServer\\execute.bat"), NULL, NULL,SW_SHOWNORMAL);       
            return 0;   
        } else {        
            MessageBox(HWND_DESKTOP, TEXT("File not found."), TEXT("Message"), MB_OK);  
            return 1;   
        }       
    }           
    

    I learned that you can test out this DLL using rundll32 (rundll32 yourdllname.dll,functionname {no space after comma}) from the command line, but only if you include a .def file in your project. My def file is

    LIBRARY
    EXPORTS
    RunPP
    

    Also, as the documentation states, I tried to add a reference to Opends60.lib in Project > Properties… > Linker > Input > Additional Dependencies, but it looks like it got removed at some point.

    For those of you as newbie as I am, I had to learn a lot of things in the project’s Property pages like switching C/C++ > Code Generation > Runtime Library to /MD. Also learning how to compile in Release mode, where to locate the resulting .dll file, etc.

    Then when moving the compiled DLL to my SQL Server machine (Win2003R2), I had to install the VC++ 2010 Redistributable for it to run. Then I copied the DLL to C:\Program Files\Microsoft SQL Server\MSSQL\Binn on my machine (same place where xp_cmdShell extended stored procedure’s DLL was), and then ran sp_addextendedproc according to the documentation to register it as an available extended stored procedure in the master database. Then granting privileges for users to execute it, etc.

    I know all this is an old technology. I should just upgrade my SQL Server version. But maybe this will help someone else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using SQL Server 2008 Enterprise version. We have a large table FooTable
I was using a older version of SQL on my server, and it worked
I am using an older version of Xcode - 3.1.3. and want to install
I'm running VS2010 SP1. We want to create a project using SQL Server Compact
I'm in SQL Server 2008 and I have been working on making some older
I have two SQL Servers (both 2005 version). I want to migrate several tables
I am stuck using the older version (2.2.1) of Jython on the machines I
I have some older (broken) code that has a join using a *= table1.ID
We currently have a 10 year old nasty, spaghetti-code-style SQL Server database that we
Subject: Migrating very complex, legacy client-server application to SAS enabled web-version using NOSQL We

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.