473,473 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VBScript can work in its own console application but cannot be called in a service?

1 New Member
The following VBScript code runs smoothly when I use cscript and/or VB console applications:

Expand|Select|Wrap|Line Numbers
  1. Set wmiServices = GetObject("winmgmts:root/default") 
  2. Set colTreeChanges = wmiServices.ExecNotificationQuery _
  3.     ("SELECT * FROM RegistryTreeChangeEvent " _
  4.     & "WHERE Hive='HKEY_LOCAL_MACHINE' " _
  5.     & "AND RootPath='SOFTWARE\\Microsoft'")
  6.  
  7. While (True)
  8.    Set TreeChange = colTreeChanges.NextEvent
  9.    TreeChange.GetObjectText_()
  10.    Wscript.Echo  "Hive = " & TreeChange.Hive & VBNewLine _
  11.       & "RootPath = "& TreeChange.RootPath _
  12.       & TreeChange.GetObjectText_()      
  13. Wend
I plan to call this code into my windows service application, it currently has the following code:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Globalization;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Management;
  10. using System.ServiceProcess;
  11. using System.Text;
  12. using System.Timers;
  13.  
  14. namespace SoftwareDetectionService
  15. {
  16.     public partial class SoftwareDetectionService : ServiceBase
  17.     {
  18.  
  19.         public SoftwareDetectionService()
  20.         {
  21.             InitializeComponent();
  22.             if (!System.Diagnostics.EventLog.SourceExists("MySource"))
  23.             {
  24.                 System.Diagnostics.EventLog.CreateEventSource(
  25.                    "MySource", "MyNewLog");
  26.             }
  27.             eventLog1.Source = "MySource";
  28.             eventLog1.Log = "MyNewLog";
  29.         }
  30.  
  31.         protected override void OnStart(string[] args)
  32.         {
  33.             eventLog1.WriteEntry("Service has started");
  34.             Process scriptproc = new Process();
  35.             scriptproc.StartInfo.RedirectStandardOutput = true;
  36.             scriptproc.StartInfo.UseShellExecute = false;
  37.             scriptproc.StartInfo.FileName = @"cscript";
  38.             scriptproc.StartInfo.Arguments = @"c:\Users\081254X\Documents\code11.vbs";
  39.             scriptproc.Start();
  40.             StreamReader SR = scriptproc.StandardOutput;
  41.             string result = SR.ReadToEnd();
  42.             eventLog1.WriteEntry(result);
  43.             scriptproc.WaitForExit();
  44.             SR.Close();
  45.             scriptproc.Close();
  46.         }
  47.  
  48.         protected override void OnStop()
  49.         {
  50.             eventLog1.WriteEntry("Service has ended");
  51.         }
  52.     }
  53. }
  54.  
For some odd reason, the VBScript code only works on cscript but when I call in the code to the service, it doesn't work... someone explain why?
Jul 5 '10 #1
3 2373
anreinor
4 New Member
do you also get the message that access (to filesystem) is denied?
Jul 9 '10 #2
!NoItAll
297 Contributor
I believe this is a security issue. Creating a service that can run VB Scripts smells like a Trojan to me...

Why not put the functionality inside the service, or wrap it into a replaceable DLL?
Jul 10 '10 #3
anreinor
4 New Member
try the following solution to access scripts from within your application:
http://msdn.microsoft.com/en-us/libr...(v=VS.60).aspx

Is a FULL description of "how-to"! Very good documentation about using scripting-engines!
Jul 12 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Chris | last post by:
Hi, Currently, I have a console application written in C# and an unmanaged legacy DLL written in VC++ 6.0. In the DLL's previous application, when an event occurs in the DLL, a windows message...
3
by: Joe | last post by:
Dear Friends, How to run the C# Console application as services? I have a console application.I want run this application as background services.User don't want see the command propmt. If anyone...
28
by: carlbono | last post by:
I need a way for my console application to stay running and be able to be called at any time with some parameters, do it's work, then wait to be called again, repeat. Here's the details: I...
0
by: Serge Bollaerts | last post by:
Hello, Some dummy questions... 1°) is it possible to an application that runs as a console application, or a windows service? For example, to execute the service I would to start it through...
1
by: kls_kumar | last post by:
Hi All, I have written a simple VB.Net Application which takes a .pst file and extracts the messages attachments from the .pst. It is working fine as a Console Application. I tried Web...
2
by: asadikhan | last post by:
I have written a console application that clears out some folders. I want this application to run as a Windows Service (not a scheduled task). What is the easiest way to convert this console...
7
by: | last post by:
Hi to everyone! I have an Apache Webserver running on Win2000. I try to start a console application an the server though PHP, with the functions exec() or passthru() but it doesn't work. The...
0
by: =?Utf-8?B?U3RldmUgTWFydGlu?= | last post by:
I am attempting to launch a console application from a service under a different set of credentials running on Windows Server 2003. I am getting an error "0xC06D007E: Module not found." from the...
0
by: sus124 | last post by:
Hello, I have a console application that I built for a filesystemwatcher in C#. I have to now convert it to a windows service. Since Express edition doesn't have an inbuilt template for windows...
5
by: codingZZ | last post by:
How do you convert a console application to a windows service.Any recommendations? The following code is below using System; using System.Collections.Generic; using System.Linq; using...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.