Chinaunix首页 | 论坛 | 博客
  • 博客访问: 362925
  • 博文数量: 35
  • 博客积分: 2176
  • 博客等级: 大尉
  • 技术积分: 797
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-13 14:03
文章分类

全部博文(35)

文章存档

2012年(9)

2009年(14)

2008年(12)

我的朋友

分类:

2009-06-10 16:28:07

使用Win32::TieRegistry
为了便于启动特定的windows服务,只是一个简单的事例。
 

use strict;

use Win32::TieRegistry( Delimiter=>"#", ArrayValues=>0 );

$Registry->Delimiter("/");

$Registry->SplitMultis();

my $done = 0;

while (1)
{
   $done = 0;

   my $key = $Registry->{"LMachine/System/CurrentControlSet/Services/DB2ADMIN"};

   if (defined $key)
   {
      $key->SetValue("ErrorControl", "0x00000000", "REG_DWORD");

      my $value = $key->GetValue("Start");

      if (!defined $value || $value ne "0x00000002")
      {
         if ($key->SetValue("Start", "0x00000002", "REG_DWORD"))
         {
            $value = $key->GetValue("Start");

            print "Windows Service 'DB2ADMIN' has been set to Autostart\n";

            $done = $done + 1;
         }
         else
         {
            print "Unable to set LMachine/System/CurrentControlSet/Services/DB2ADMIN/Start\n$^E\n";
         }
      }
      else
      {
         print "Windows Service 'DB2ADMIN' was already set to Autostart\n";

         $done = $done + 1;
      }
   }

   exit(0) if ($done >= 2);

   sleep 15*60;
}

阅读(981) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~