Marius
Thu Dec 04 02:25:33 CST 2003
Infinite thanks for you answer and all ther useful information you provided.
Marius
"Alex K. Angelopoulos [Server MVP]" <aka-at-mvps-dot-org> wrote in message
news:OM59%23UYuDHA.2224@TK2MSFTNGP09.phx.gbl...
> Marius from Rome wrote:
> > Let me ask 3 questions, a general and 2 more specific questions.
> >
> > The first general question is: how can I call a function existing in a
> > .dll file from a VBscript file? How can I insert the reference to the
> > .dll file? Is there any documentation available?
>
> You made no mistakes; you just can't do this.
>
> The DLL functions you are referring to are API calls, which can't be done
> from script. There are workarounds for this general class of problem
which
> are workable for your case; a binary allowing API calls which you could
> install is available here:
>
http://home.att.net/~wshvbs/wshAPIToolkitObjectPage.htm
>
> And you could also write a COM class (an OCX or a COM DLL) that wraps the
> APIU call for access; this can be done in VB5 or 6, but could be
complicated
> for you without some COM and API experience even if you have access to a
> compiler.
>
> > The more specific question is: I need to detect if my script is running
> > in a terminal services session. I read article
> >
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/termserv/termserv/detecting_the_terminal_services_environment.asp
> > that suggests to use the GetSystemMetrics function, thast looks to fit
> > my needs: how can I call such function from my VBscript?
>
> You asked the wrong question here. The right question is "how do I detect
> if my script is running in a Terminal Services Session?"
>
> The simplest answer from a scripting context is this: there is an
> environment variable automatically created in ALL sessions on TS systems,
> named %CLIENTNAME%.
>
> You can retrieve this easily using WshShell's ExpandEnvironmentStrings
> method. If it does not exist, the unexpanded string is returned; if it
> does, it returns the name of the client PC. One IMPORTANT warning: if you
> are connected to the console on a system running TS or Remote Desktop,
this
> variable exists, and has the value "Console", so check for that case
before
> treating it like it is in a TS session!
>
> Here's a simple demo function that returns true-false for being in a
remote
> session.
>
> WScript.Echo IsRemoteSession()
>
> function IsRemoteSession()
> dim sh: set sh = createobject("WScript.Shell")
> dim shellvar: shellvar = "%clientname%"
> dim client: client = lcase( sh.ExpandEnvironmentStrings(shellvar) )
> ' Value of client will be "console" in a console session;
> ' on a system which does not have the variable in the environment
> ' (and thus is not running TS) it will return "%clientname%".
> ' WScript.echo client ' uncomment this line for debugging
> if client <> shellvar and client <> "console" then
> IsRemoteSession = true
> else
> IsRemoteSession = false
> end if
> end function
>
>
> > The second more specific question is: I used the Object Browser of Word
> > to see the details of the wtsapi32.dll objects, but if I try to add it
> > to the list of my references I get a message saying that it can't add a
> > reference to the specific file. What is my mistake?
>
> I noted before that you made no mistake; you just didn't know something,
> which is easy to fix. :)
>
> What you can view in the object browsers are COM DLLs. Standard DLLs
don't
> have COM interfaces; you run into the same problem with kernel32, user32,
> and similar DLLs which are only accessible via API calls.
>
>