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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling GetWindowText causes a SecurityException on deployment machine 1

Status
Not open for further replies.

dalchri

Programmer
Apr 19, 2002
608
US
I have the following API call in one of the inherited windows forms classes:

Code:
[DllImport("user32.dll", CharSet=CharSet.Auto)]
static extern int GetWindowText(HandleRef hnd, StringBuilder str, int intMaximum);

Whenever I call this function on the developer machine, I am fine. However, when I call it on the deployment machine, I get the following exception:

"The application attempted to perform an operation not allowed by the security policy. The operation required the SecurityException. To grant this application the required permission please contact your system administrator, or use the Microsoft .NET security policy administration tool."

I prefer not to have to perform some sort of manual security configuration on each of my deployment targets.

Is there a way to address this problem in code through the use of class or member attributes?

Thank you for any pointers!
 
Further information:

The problem is that the deployment targets are running the program off of a network drive. The development machine was running the application locally.

The question remains, can I address this problem with code rather than reconfigure each and every deployment target?

FYI, the reason I use a network drive is so that I can upgrade all clients at once using XCopy.

Thanks for any info!
 
For your deployment solution and without any change of code there is an work around.
Let say, the GBSTOCK application is stored on a remote machine under a shared folder.
So there is \GBSTOCK folder which contains GBSTOCK.EXE, GBSTOCK.EXE.CONFIG, GBFRamework.dll etc...
A user have access to that shared folders and want to execute the GBSTOCK.EXE.
The solution is to have a .bat file on the local machine, let say gbstock.bat and a shortcut to it created
on the desktop. The user click on the icon and the gbstock.bat queries all the remote \GBSTOCK files and stores these
files on the local machine.
When copy is finished starts automatically the GBSTOCK.EXE.
That is all!
Here is an example of such .bat file for the \GBSTOCK folder stored on a remote machine named GEORGE90 where the \ACSUPPORT$ is a shared folder on that machine
When called, it does:
-copy remote files on the local machine
-launch the GBSTOCK application
Code:
@ECHO OFF
SET          SERVER=GEORGE90
SET         VERSION=Version 1.1
SET APP_REMOTE_PATH=\\%SERVER%\ACSUPPORT$\GBSTOCK
SET        APP_DIR0=C:\GBSTOCK_REMOTE
SET        APP_DIR1=GBSTOCK
SET  APP_LOCAL_PATH=%APP_DIR0%\%APP_DIR1%
SET         APP_EXE=GBSTOCK.EXE
SET      APP_CONFIG=GBSTOCK.EXE.CONFIG
SET  APP_FRAME_WORK=GBFrameWork.dll
SET             PRG=%0%

REM LOCAL DIRECTORY VALIDATION
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~
IF NOT EXIST %APP_DIR0% MKDIR %APP_DIR0%
IF NOT EXIST %APP_DIR0%\%APP_DIR1% MKDIR %APP_DIR0%\%APP_DIR1%

REM REMOTE FILES VALIDATION
REM ~~~~~~~~~~~~~~~~~~~~~~~~~~
IF NOT EXIST %APP_REMOTE_PATH% GOTO ERR_REMOTE_PATH
IF NOT EXIST %APP_REMOTE_PATH%\%APP_EXE% GOTO ERR_REMOTE_EXE
IF NOT EXIST %APP_REMOTE_PATH%\%APP_FRAME_WORK% GOTO ERR_REMOTE_FRAMEWORK
IF NOT EXIST %APP_REMOTE_PATH%\%APP_CONFIG% GOTO ERR_REMOTE_CONFIG

CLS
ECHO.
ECHO GBSTOCK Remote Execution - %VERSION%
ECHO.
ECHO This process will connect to production server (%APP_REMOTE_PATH%) 
ECHO copy GBSTOCK program and config files locally, then will start
ECHO GBSTOCK locally.
ECHO.
ECHO.
ECHO To cancel this operation, press CTRL+C and type Y
ECHO.
ECHO.
PAUSE

ECHO.
ECHO. COPYING FILE LOCALY...
COPY %APP_REMOTE_PATH%\%APP_EXE% %APP_LOCAL_PATH%\%APP_EXE%
COPY %APP_REMOTE_PATH%\%APP_FRAME_WORK% %APP_LOCAL_PATH%\%APP_FRAME_WORK%
COPY %APP_REMOTE_PATH%\%APP_CONFIG% %APP_LOCAL_PATH%\%APP_CONFIG%
ECHO.
ECHO. STARTING THE APPLICATION...
%APP_LOCAL_PATH%\%APP_EXE% 
GOTO END

:ERR_REMOTE_PATH
ECHO.
ECHO ERROR
ECHO.
ECHO REMOTE PATH %APP_REMOTE_PATH% do not exist.
ECHO.
ECHO.
GOTO PPAUSE

:ERR_REMOTE_EXE
ECHO.
ECHO ERROR
ECHO.
ECHO REMOTE EXE %APP_REMOTE_PATH%\%APP_EXE% do not exist.
ECHO.
ECHO.
GOTO PPAUSE

:ERR_REMOTE_FRAMEWORK
ECHO.
ECHO ERROR
ECHO.
ECHO GBFrameWork %APP_REMOTE_PATH%\%APP_FRAME_WORK% do not exist.
ECHO.
ECHO.
GOTO PPAUSE

:ERR_REMOTE_CONFIG
ECHO.
ECHO ERROR
ECHO.
ECHO REMOTE CONFIG %APP_REMOTE_PATH%\%APP_CONFIG% do not exist.
ECHO.
ECHO.
:PPAUSE
PAUSE
GOTO END

:END
So for your case, modify this .bat file to point to the right server, shared folder, application and files required by application to run.
Create a shortcut to that .bat and click on it. You should see the app running.
This is an acceptable work around but you should implement the strong name key and deploy it on the user machines.
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top