PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.sqlserver.server > Setting environment variables with xp_cmdshell
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Setting environment variables with xp_cmdshell

Réponse
 
LinkBack Outils de la discussion
Vieux 18/06/2008, 10h58   #1
OlivieCora
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Setting environment variables with xp_cmdshell

Hello,

I am trying to change the value of an environment (MSSQL service user)
variable with the following tsql:

exec master..xp_cmdshell 'SET test=test'

unfortunately the variable is not changed; anyone would know why this
doesn't work?

how can I achieve this?

thanks and regards,

Olivier.
  Réponse avec citation
Vieux 18/06/2008, 14h05   #2
Linchi Shea
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: Setting environment variables with xp_cmdshell

An enviornment variable set with the SET command is temporary to the command
prompt session. A new execution of xp_cmdshell invokes a new session. If you
want the environment variable setting to be permanent, you need to edit the
registry or use COntrol Panel || System:Advanced:Environment Variables.

Windows Resource kit does have command-line utility called SETX.EXE, which
you can invoke from xp_cmdshell.

Linchi

"OlivieCora" wrote:

> Hello,
>
> I am trying to change the value of an environment (MSSQL service user)
> variable with the following tsql:
>
> exec master..xp_cmdshell 'SET test=test'
>
> unfortunately the variable is not changed; anyone would know why this
> doesn't work?
>
> how can I achieve this?
>
> thanks and regards,
>
> Olivier.

  Réponse avec citation
Vieux 18/06/2008, 14h31   #3
John Bell
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Setting environment variables with xp_cmdshell


"OlivieCora" <OlivieCora@discussions.microsoft.com> wrote in message
news:5FEA7CBE-5038-40C9-A73A-B6F1CE49E115@microsoft.com...
> Hello,
>
> I am trying to change the value of an environment (MSSQL service user)
> variable with the following tsql:
>
> exec master..xp_cmdshell 'SET test=test'
>
> unfortunately the variable is not changed; anyone would know why this
> doesn't work?
>
> how can I achieve this?
>
> thanks and regards,
>
> Olivier.


Hi

The environment variable will be set for the extent of invocation of
xp_cmdshell e.g

if you create a file C:\temp\fred.bat containing
@@echo off
SET test=ttt
echo %test%

From

EXEC xp_cmdshell 'C:\temp\fred.bat'

You would get
output
-------
ttt
NULL

Change fred.bat to
@@echo off
echo %test%

output
-------
ECHO is off.
NULL

i.e the original SET is no longer valid.

If you want to have something picked up in other xp_cmdshells you could
either change the registry or use a file and materialise the values in that,
The third alternative is to specify them in the command itself each time e.g
write a batch script that takes parameters.

John

  Réponse avec citation
Vieux 18/06/2008, 14h37   #4
OlivierCora
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: Setting environment variables with xp_cmdshell

Hi Linchi Shea,
that's what I figured out... SETX is exactly what I was looking for

thanks a lot!

Olivier.

"Linchi Shea" wrote:

> An enviornment variable set with the SET command is temporary to the command
> prompt session. A new execution of xp_cmdshell invokes a new session. If you
> want the environment variable setting to be permanent, you need to edit the
> registry or use COntrol Panel || System:Advanced:Environment Variables.
>
> Windows Resource kit does have command-line utility called SETX.EXE, which
> you can invoke from xp_cmdshell.
>
> Linchi
>
> "OlivieCora" wrote:
>
> > Hello,
> >
> > I am trying to change the value of an environment (MSSQL service user)
> > variable with the following tsql:
> >
> > exec master..xp_cmdshell 'SET test=test'
> >
> > unfortunately the variable is not changed; anyone would know why this
> > doesn't work?
> >
> > how can I achieve this?
> >
> > thanks and regards,
> >
> > Olivier.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 04h38.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14072 seconds with 12 queries