wincc 通过vbs来启动windows服务

wincc判断系统服务运行状态,重启服务的例子:

 If (HMIRuntime.Tags("@PRF_CLDCN_TAG_FAILED_WRITES_TOTAL").Read > 0) Then
 	strComputer = "." 
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
	Set colServiceList = objWMIService.ExecQuery _ 
	    ("Select * from Win32_Service where Name = 'CCCloudConnect'") 
	For Each objService In colServiceList 
	Msgbox(objService.State)
	    If objService.State = "Running" Then 
	        objService.StopService() 
	        Wscript.Sleep 5000
	        objService.StartService() 
	    End If 
	    'errReturnCode = objService.ChangeStartMode("Disabled")    
	Next
	Msgbox("ok")
 End If



strComputer = "."
	Set objWMIService = GetObject("winmgmts:" _
	    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set colServiceList = objWMIService.ExecQuery _
	    ("Select * from Win32_Service where Name='CCCloudConnect'")
	For each objService in colServiceList
	    errReturn = objService.StartService()
	Next
	Wscript.Sleep 20000
	Set colServiceList = objWMIService.ExecQuery("Associators of " _
	   & "{Win32_Service.Name='CCCloudConnect'} Where " _
	        & "AssocClass=Win32_DependentService " & "Role=Dependent" )
	For each objService in colServiceList
	    objService.StartService()
	Next

发表在 待分类 | wincc 通过vbs来启动windows服务已关闭评论

Windows带密码的账户自动登录

一些带密码的系统,需要设置自动登录,在新系统里这部分功能是隐藏了的,老系统可以直接设置。现在需要改注册表的方式来实现。

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"AutoAdminLogon"="1"
"DefaultUserName"="wincc"
"DefaultPassword"="123"

将用户名和密码改成实际需要自动登录的用户和密码,保存为.reg文件,导入注册表就可以了。

发表在 待分类 | Windows带密码的账户自动登录已关闭评论

自动pptp连接

win7测试成功得pptp自动连接方法。

1、创建vpn连接,保存用户名和密码,确保手动可以连接成功。

2、VPN连接最好可以指定客户端获取得ip地址,这样填写静态路由时方便一些。

3、pptp连接后在属性中ipv4的默认网关属性去掉。

4、cmd运行, route add 192.168.0.0 mask 255.255.255.0 10.0.0.20 -p
-p 参数用于持久化该配置,重启后该路由还存在。

另一种写法,用route print 列出所有网卡,得到网卡号。
route add 192.168.9.0 mask 255.255.255.0 10.0.0.1 if 36
指定网卡号的方式来指定路由出口。
route add 192.168.9.0 mask 255.255.255.0 10.0.0.1
指定vpn网关的方式指定路由出口。

5、创建一个开机后运行的计划任务,rasdial VPN连接名 用户名 密码
该计划任务条件为当本地连接后执行,执行失败后每分钟重试执行,3次以上。

发表在 待分类 | 自动pptp连接已关闭评论

asp 数据库转json代理

<%@ LANGUAGE = VBScript CodePage = 65001%>
<%
class JSON
private output, innerCall
public toResponse        ''[bool] should generated results be directly written to the response? default = false
public sub class_initialize()
        newGeneration()
        toResponse = false
end sub
public function escape(val)
dim cDoubleQuote, cRevSolidus, cSolidus
        cDoubleQuote = &h22
        cRevSolidus = &h5C
        cSolidus = &h2F
dim i, currentDigit
for i = 1 to (len(val))
            currentDigit = mid(val, i, 1)
if ascw(currentDigit) > &h00 and ascw(currentDigit) < &h1F then
                currentDigit = escapequence(currentDigit)
elseif ascw(currentDigit) >= &hC280 and ascw(currentDigit) <= &hC2BF then
                currentDigit = "\u00" + right(padLeft(hex(asc(currentDigit) - &hC200), 2, 0), 2)
elseif ascw(currentDigit) >= &hC380 and ascw(currentDigit) <= &hC3BF then
                currentDigit = "\u00" + right(padLeft(hex(ascw(currentDigit) - &hC2C0), 2, 0), 2)
else
select case ascw(currentDigit)
case cDoubleQuote: currentDigit = escapequence(currentDigit)
case cRevSolidus: currentDigit = escapequence(currentDigit)
case cSolidus: currentDigit = escapequence(currentDigit)
end select
end if
            escape = escape & currentDigit
next
end function
public function toJSON(name, val, nested)
if not nested and not isEmpty(name) then write("{")
if not isEmpty(name) then write("""" & escape(name) & """: ")
        generateValue(val)
if not nested and not isEmpty(name) then write("}")
        toJSON = output
if innerCall = 0 then newGeneration()
end function
private function generateValue(val)
if isNull(val) then
            write("null")
elseif isArray(val) then
            generateArray(val)
elseif isObject(val) then
if val is nothing then
                write("null")
elseif typename(val) = "Dictionary" then
                generateDictionary(val)
elseif typename(val) = "Recordset" then
                generateRecordset(val)
else
                generateObject(val)
end if
else
'bool
            varTyp = varType(val)
if varTyp = 11 then
if val then write("true") else write("false")
'int, long, byte
elseif varTyp = 2 or varTyp = 3 or varTyp = 17 or varTyp = 19 then
                write(cLng(val))
'single, double, currency
elseif varTyp = 4 or varTyp = 5 or varTyp = 6 or varTyp = 14 then
                write(replace(cDbl(val), ",", "."))
else
                write("""" & escape(val & "") & """")
end if
end if
        generateValue = output
end function

private sub generateArray(val)
dim item, i
        write("[")
        i = 0
'the for each allows us to support also multi dimensional arrays
for each item in val
if i > 0 then write(",")
            generateValue(item)
            i = i + 1
next
        write("]")
end sub
private sub generateDictionary(val)
dim keys, i
        innerCall = innerCall + 1
        write("{")
        keys = val.keys
for i = 0 to uBound(keys)
if i > 0 then write(",")
            toJSON keys(i), val(keys(i)), true
next
        write("}")
        innerCall = innerCall - 1
end sub
'*******************************************************************
'* generateRecordset
'*******************************************************************
private sub generateRecordset(val)
dim i
        write("[")
while not val.eof
            innerCall = innerCall + 1
            write("{")
for i = 0 to val.fields.count - 1
if i > 0 then write(",")
                toJSON lCase(val.fields(i).name), val.fields(i).value, true
next
            write("}")
            val.movenext()
if not val.eof then write(",")
            innerCall = innerCall - 1
wend
        write("]")
end sub
'*******************************************************************************
'* generateObject
'*******************************************************************************
private sub generateObject(val)
dim props
on error resume next
set props = val.reflect()
if err = 0 then
on error goto 0
            innerCall = innerCall + 1
            toJSON empty, props, true
            innerCall = innerCall - 1
else
on error goto 0
            write("""" & escape(typename(val)) & """")
end if
end sub
'*******************************************************************************
'* newGeneration
'*******************************************************************************
private sub newGeneration()
        output = empty
        innerCall = 0
end sub
'*******************************************************************************
'* JsonEscapeSquence
'*******************************************************************************
private function escapequence(digit)
        escapequence = "\u00" + right(padLeft(hex(asc(digit)), 2, 0), 2)
end function
'*****************************************************************************
'* padLeft
'*****************************************************************************
private function padLeft(value, totalLength, paddingChar)
        padLeft = right(clone(paddingChar, totalLength) & value, totalLength)
end function
'*****************************************************************************
'* clone
'******************************************************************************************
public function clone(byVal str, n)
dim i
for i = 1 to n : clone = clone & str : next
end function
'******************************************************************************************
'* write
'******************************************************************************************
private sub write(val)
if toResponse then
            response.write(val)
else
            output = output & val
end if
end sub
end class  
          
response.ContentType="text/json"
dim j
'多重嵌套的JSON,要使用Dictionary才能实现
set j=new json
set jso=server.createobject("scripting.dictionary")

dbstr = request("dbstr") 			'设置每页显示的记录数
if dbstr = "" then dbstr = "driver={SQL Server};Server=;UID=yxbl;PWD=yxbl;database=GlassQualityTest"
'if dbstr = "" then dbstr = "DSN=sql;Database=GlassQualityTest;UID=yxbl;PWD=yxbl;"
conn()
function conn()
	dim conn1,connstr
	on error resume next
		set conn1 = Server.CreateObject("ADODB.Connection") 
		conn1.open dbstr
	if err <> 0 then
    jso.add "dbstr",dbstr
		jso.add "err",err.description
		response.write j.toJSON(empty,jso,false)
		response.end
	end if
	set conn = conn1
end function
Sub echo(str)
	Response.Write(str)
End Sub
'正则表达式函数,用于删除注释
'-------------------------------------
Function RegExpReplace(strng, patrn, replStr)
  Dim regEx,match,matches              ' 建立变量。
  Set regEx = New RegExp               ' 建立正则表达式。
  regEx.Pattern = patrn               ' 设置模式。
  regEx.IgnoreCase = True               ' 设置是否区分大小写。
  regEx.Global = True   ' 设置全局可用性。
  RegExpReplace = regEx.Replace(strng, replStr)         ' 作替换。
End Function
'==================================================================显示查询
sub showselect(sql)
	dim page,pageUrl,strdel,geturl					
	pageSize = request("pageSize") 			'设置每页显示的记录数
	if pageSize = "" or not isNumeric(pageSize) then pageSize = 500
	page = request("page")           '设置当前显示的页数
	if page="" or not isNumeric(page) then page=1
	pageUrl = "?sql=" & Server.URLEncode(sql)
   dim rs
   set rs = Server.CreateObject("ADODB.Recordset")
   rs.Open sql,conn,3
   if not rs.eof then
   	  rs.pageSize = pageSize
	  if cint(page) < 1 then page = 1
   	  if cint(page) > rs.PageCount then page = rs.PageCount
   	  rs.absolutePage = page
   end if
   set pag=server.createobject("scripting.dictionary")
	  pag.add "page",page
	  pag.add "pageSize",pageSize
	  pag.add "recordCount",rs.recordCount
	  pag.add "PageCount",rs.PageCount
	  jso.add "page",pag
    jso.add "rs",rs
end sub
sub exesql(sql)
	on error resume next
	if sql = "" then exit sub
    sql = RegExpReplace(sql, "(--)(.)*\n", "")   '替换注释
    sql = RegExpReplace(sql, "\n[\s| ]*\r", "")  '替换空行
    sql = RegExpReplace(sql, "\n", "")           '替换换行符
    sql = RegExpReplace(sql, "\r", "")           '替换回车符
    if (LCase(left(sql,len("select"))) = "select") and instr(sql,"into") = 0 then '只允许select
     Call showSelect (sql)
	   if err <> 0 then 
       jso.add "sql",trim(request("sql"))
       jso.add "err",err.description
       response.write j.toJSON(empty,jso,false)
       response.end
     end if
    end if
end sub
  call exesql(trim(request("sql")))
  response.write j.toJSON(empty,jso,false)
%>
发表在 待分类 | asp 数据库转json代理已关闭评论

安装tdengine

下载:
wget https://www.taosdata.com/download/download-gettingStarted.php?pkg=tdengine_rpm -O TD.rpm
安装:
rpm -ivh TD.rpm

配置文件:
vi /etc/taos/taos.cfg
修改maxSQLLength 1000000,1M,sql语句最大长度
启动:
sudo systemctl start taosd

发表在 待分类 | 安装tdengine已关闭评论

influxDB安装

下载地址:
https://portal.influxdata.com/downloads/

centos安装:

wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.1.x86_64.rpm
sudo yum localinstall influxdb-1.8.1.x86_64.rpm

启动:

systemctl enable influxdb
systemctl start influxdb

使用:

influx命令可以显示当前版本,默认webapi端口号为8086,需要防火墙放行才能外网访问。

php扩展:

https://github.com/influxdata/influxdb-php

发表在 待分类 | influxDB安装已关闭评论

linux挂载磁盘

系统增加一块硬盘后,需要挂载和格式化。

fdisk -l

查看磁盘列表

分区后的磁盘有sda1、sda2等分区,不存在的就是没有分区

fdisk  /dev/sdb

n->p->1->回车->回车->w

分区完成后进行格式化

mkfs.ext4 /dev/sdb1

mkdir /mntdir 创建一个目录

mount /dev/vdb1  /mntdir 挂载磁盘到目录

df 查看磁盘信息

重启后自动挂载

vim /etc/fstab

//打开后,在最后一行加入以下代码:

/dev/vdb1 /mutdir ext4 defaults 0 1 

宝塔面板的一键挂载

yum install wget -y && wget -O auto_disk.sh http://download.bt.cn/tools/auto_disk.sh && bash auto_disk.sh

增加容量的方法

在虚拟机对磁盘进行扩容,扩容后对需要扩容的磁盘进行分区的重新编辑

fdisk /dev/sdb1
d #删除分区
n #创建分区
p #创建主分区,输入分区号1,起始扇区,结束扇区。一般默认
w #写入分区

重启,执行resize2fs /dev/sdb1 再通过查看df -h查看是否成功

发表在 待分类 | linux挂载磁盘已关闭评论

ESXI 提示coredump问题

执行:esxcli system coredump file add
执行: esxcli system coredump file list

提示:/vmfs/volumes/5ec0a9d5-f6305204-6fb0-40f2e997ffc2/vmkdump/05973FF6-6FBF-11E3- AA06-40F2E997FFC2.dumpfile false false 2529165312

执行:esxcli system coredump file set -p /vmfs/volumes/5ec0a9d5-f6305204-6fb0-40f2e997ffc2/vmkdump/05973FF6-6FBF-11E3-AA06-40F2E997FFC2.dumpfile

发表在 待分类 | ESXI 提示coredump问题已关闭评论

python tkinter的全屏使用

import tkinter
import threading
#按F11切换全屏,ESC退出全屏
class FullScreenApp(object):
    def __init__(self, master, **kwargs):
        self.root = master
        # self.tk.attributes('-zoomed', True)  # This just maximizes it so we can see the window. It's nothing to do with fullscreen.
        self.frame = tkinter.Frame(self.root)
        self.frame.pack()
        self.state = False
        self.root.bind("<F11>", self.toggle_fullscreen)
        self.root.bind("<Escape>", self.end_fullscreen)

    def toggle_fullscreen(self, event=None):
        self.state = not self.state  # Just toggling the boolean
        self.root.attributes("-fullscreen", self.state)
        return "break"

    def end_fullscreen(self, event=None):
        self.state = False
        self.root.attributes("-fullscreen", False)
        return "break"

win=tkinter.Tk()
win.title("实时运行窗口")
#根据显示器分辨率自动全屏窗口
w = win.winfo_screenwidth()
h = win.winfo_screenheight()
win.geometry("%dx%d" %(w,h))
win.attributes("-fullscreen",True)
app=FullScreenApp(win)

def fun_timer():
    print('hello timer')   #打印输出
    global timer  #定义变量
    timer = threading.Timer(2,fun_timer)   #60秒调用一次函数
    #定时器构造函数主要有2个参数,第一个参数为时间,第二个参数为函数名
    timer.start()    #启用定时器
    
timer = threading.Timer(1,fun_timer)  #首次启动
timer.start()

cv = tkinter.Canvas(win,background='white')
cv.pack()
cv.create_rectangle(30, 30, 200, 200,
    outline='red', # 边框颜色
    stipple = 'question', # 填充的位图
    fill="red", # 填充颜色
    width=5 # 边框宽度
    )
cv.create_oval(240, 30, 330, 200,
    outline='yellow', # 边框颜色
    fill='pink', # 填充颜色
    width=4 # 边框宽度
    )
cv.create_rectangle(50, 20, 150, 80, fill="#476042")
cv.create_rectangle(65, 35, 135, 65, fill="yellow")
cv.create_line(0, 0, 50, 20, fill="#476042", width=3)
cv.create_line(0, 100, 50, 80, fill="#476042", width=3)
cv.create_line(150,20, 200, 0, fill="#476042", width=3)
cv.create_line(150, 80, 200, 100, fill="#476042", width=3)
cv.create_text(60,40,text= "hi, i am string", font = "time 10 bold underline", tags = "string")

points = [100, 140, 110, 110, 140, 100, 110, 90, 100, 60, 90, 90, 60, 100, 90, 110]

cv.create_polygon(points, outline="#476042", 
            fill='yellow', width=3)
#img = tkinter.PhotoImage(file="1.jpg")
#cv.create_image(20,20, image=img)

label = tkinter.Label(win,text = '爷来了')
label.pack()
# win:父窗体
# text:显示的文本内容
# bg:背景色
# fg:字体颜色
# font:字体
# wraplength:指定text文本中多宽之后换行
# justify:设置换行后的对齐方式
# anchor:位置 n北,e东,w西,s南,center居中;还可以写在一起:ne东北方向
label = tkinter.Label(win,
                      text="this is a word",
                      bg="pink", fg="red",
                      font=("黑体", 20),
                      width=20,
                      height=10,
                      wraplength=100,
                      justify="left",
                      anchor="ne")

# 显示出来
label.pack()


li     = ['C','python','php','html','SQL','java']
movie  = ['CSS','jQuery','Bootstrap']
listb  = tkinter.Listbox(win)          #  创建两个列表组件
listb2 = tkinter.Listbox(win)
for item in li:                 # 第一个小部件插入数据
    listb.insert(0,item)
 
for item in movie:              # 第二个小部件插入数据
    listb2.insert(0,item)
 
listb.pack()                    # 将小部件放置到主窗口中
listb2.pack()

label1 = tkinter.Label(win, text="柳多妍", bg="pink")

label2 = tkinter.Label(win, text="多多", bg="yellow")

label3 = tkinter.Label(win, text="超级飞侠", bg="red")

# label1.pack()   # #默认没有布局,字有多长,背景也有多长,和其他label错落显示
# label2.pack()
# label3.pack()

label1.place(x=10, y=10)   # #固定坐标,按绝对布局显示,窗口大小的变化对布局没有影响
label2.place(x=50, y=50)
label3.place(x=100, y=100)



label1.config(text="NEW")


win.mainloop()
发表在 待分类 | python tkinter的全屏使用已关闭评论

树莓派开机自动运行vncviewer

一般都是电脑连接树莓派进行管理,我这次是使用树莓派自动远程电脑后显示其它远程桌面的内容作为远程显示器使用,这就要开机自动运行vncview。

树莓派官方系统,首先安装vncview,系统自带了server端,软件里很方便的就可以安装上viwer端。

远程windows服务器端我选用tightVNC1.3版本,realvnc测试连接正常。密码设置为无,且允许无密码连接。正常运行winvnc就好了。

在自动运行桌面的用户目录下进入/home/pi/.config/autostart目录,创建文件VNC.desktop

[Desktop Entry]
Type=Application
Name=VNC自动启动
Comment=自动启动VNCvierer
NoDisplay=false
Exec=sudo sh /home/pi/vnc.sh
NotShowIn=GNOME;KDE;XFCE;
Name[zh_CN]=VNC自动启动

创建/home/pi/vnc.sh文件

while true
do
        ping -c 1 -w 1 172.16.80.20
        if [ $? != 0 ];then     
                echo " ping fail "
                sleep 1
        else                   
		sudo vncviewer -FullScreen 172.16.80.20
        fi                                
                                          
done

延伸:取消屏保

进入目录:cd /etc/lightdm
1.sudo chmod 777 lightdm.conf
2.配置文件增加行:xserver-command=X -s 0 -dpms
3.重启生效
发表在 待分类 | 树莓派开机自动运行vncviewer已关闭评论