word的锁定与解锁

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Net.Mime;
 6 using System.ComponentModel;
 7 using System.IO;
 8 using Microsoft.Office.Interop.Word;
 9 using MSWord = Microsoft.Office.Interop.Word;
10 using Microsoft.Office.Tools.Word;
11 //using Word = Microsoft.Office.Interop.Word;
12
13
14 namespace ConsoleApplication4
15 {
16     class Program
17     {
18         static void Main(string[] args)
19         {
20             string fileName = "D:\\测试.doc";
21             string passWord = "112233";
22             Protect(passWord, fileName);
23             Unprotected(passWord, fileName);
24         }
25
26         public static void Protect(string passWord,string FileName)
27         {
28             MSWord.Application WordApp;
29             MSWord.Document WordDoc;
30             try{
31                 object missing = Type.Missing;
32                 WordApp = new MSWord.ApplicationClass();
33                 object fileName = FileName ;
34                 object readOnly = false;
35                 object isVisible = true;
36                 object objFalse = false;
37                 WordApp.CommandBars["Control Toolbox"].Enabled = false;
38                 //打开文档
39                 WordDoc = WordApp.Documents.Open(ref fileName ,
40                     ref missing,ref readOnly ,ref missing ,ref missing ,ref missing,
41                     ref missing ,ref missing ,ref missing ,ref missing ,ref missing,
42                     ref missing ,ref missing , ref isVisible ,ref missing ,ref missing );
43                 object objProtectPWD = passWord ;
44                 object NoSet = null;
45                 WordDoc .Protect2002(WdProtectionType.wdAllowOnlyFormFields,ref NoSet,ref objProtectPWD);
46                 WordDoc .Save();
47                 WordDoc .Close(ref missing,ref missing,ref missing);
48                 WordApp.Quit(ref missing, ref missing, ref missing);
49             }
50             catch(Exception ex)
51             {
52             }
53         }
54
55         public static void Unprotected(string passWord, string FileName)
56         {
57             MSWord.Application WordApp;
58             MSWord.Document WordDoc;
59             WordApp = new MSWord.ApplicationClass();
60             WordApp.CommandBars["Control Toolbox"].Enabled = true ;
61             object PassWord = passWord;
62             object fileName = FileName;
63             object missing = Type.Missing;
64             object readOnly = false;
65             object isVisible = true;
66             object objFalse = false;
67             WordDoc = WordApp.Documents.Open(ref fileName,
68                     ref missing, ref readOnly, ref missing, ref missing, ref missing,
69                     ref missing, ref missing, ref missing, ref missing, ref missing,
70                     ref missing, ref missing, ref isVisible, ref missing, ref missing);
71             WordDoc.Activate();
72             //检查是否有密码
73             if (WordDoc.HasPassword)
74             {
75                 WordDoc.Password = null;
76             }
77             //检查是否为Word文档设置保护功能,没有设置保护功能则直接解除密码保护
78             if (WordDoc.ProtectionType != WdProtectionType.wdNoProtection)
79             {
80                 WordDoc.Unprotect(ref PassWord);
81             }
82
83             WordDoc.Save();
84             WordDoc.Close(ref missing, ref missing, ref missing);
85             WordApp.Quit(ref missing, ref missing, ref missing);
86          }
87
88     }
89 }

word的锁定与解锁

时间: 2024-10-27 13:47:46

word的锁定与解锁的相关文章

统计 iOS 设备锁定、解锁次数-b

今天下了个软件,可以记录手机解锁的次数和使用时间,当然啦,App 必须在后台运行着.当时比较纳闷的是有什么 API 可以接收设备解锁事件或通知的,Google 了下,还真有哎——我是链接:http://stackoverflow.com/questions/14229955/is-there-a-way-to-check-if-the-ios-device-is-locked-unlocked?noredirect=1&lq=1. 设备锁定的状态 由上面的回答可以知道,设备在锁定.解锁的时候,S

Oracle数据库对象查询是否被锁定及解锁

Oracle数据库对象是否被锁定查询SQL及解锁过程SQL详见下面: --查询当前用户下被锁的对象SELECT B.OBJECT_NAME, B.OWNER, C.SID,C.SERIAL#,C.OSUSER, C.MACHINE, C.TERMINAL  FROM V$LOCKED_OBJECT A, DBA_OBJECTS B, V$SESSION C WHERE A.OBJECT_ID = B.OBJECT_ID   AND A.SESSION_ID = C.SID   AND c.STA

实现普通用户修改用户密码、锁定、解锁!

#!/bin/bash ###--------------Program theme-------------###### # #本Shell,是为了实现普通用户可以修改用户账户密码更改.锁定.解锁,制定的脚步. while : do clear cat <<xue  =============================================== / Y2c015 user administration \| 1) user change password | | 2) use

linux系统用户锁定与解锁

1.使用passwd命令锁定与解锁账号 [[email protected] ~]# passwd -l lxj --- -l 锁定 Locking password for user lxj. passwd: Success [[email protected] ~]# passwd -S lxj --- 查看状态 lxj LK 2016-06-20 0 99999 7 -1 (Password locked.) [[email protected] ~]# [[email protected

使用Pam_Tally2锁定和解锁SSH失败的登录尝试

am_tally2模块用于某些数对系统进行失败的ssh登录尝试后锁定用户帐户. 此模块保留已尝试访问的计数和过多的失败尝试. pam_tally2模块有两个部分,一个是pam_tally2.so,另一个是pam_tally2. 它是基于PAM模块上,并且可以被用于检查和调节计数器文件. 它可以显示用户登录尝试次数,单独设置计数,解锁所有用户计数. Pam_tally2锁定SSH登录 默认情况下,pam_tally2模块已经安装在大多数Linux发行版,它是由PAM包本身的控制. 本文演示如何锁定

Oracle锁定和解锁用户的命令

转:http://database.51cto.com/art/200910/158576.htm 在DBA的日常工作中,经常遇到为Oracle用户解锁的操作:这篇文章给出在命令行下进行Oracle用户解锁的操作方法,通过几条简单的解锁语句就能完成此项工作.下面是具体的过程: 默认的scott用户是被锁定的,先解锁就能登陆上了. 使用下面的语句解锁scott: alter user scott account unlock; 解锁之后可能会要求你该密码: alter user scott ide

【分享】AIX用户账户锁定与解锁

例如:密码多次被输错,锁定后的提示信息Password:530-There have been too many unsuccessful login attempts; please see        the system administrator. 与之相关的配置参数是/etc/security/login.cfg的以下配置项 logindisable=7              *7次失败登录后锁定端口logininterval=120            *在120秒内7次失败

Oracle查看表锁定及解锁

在对Oracle数据库的Update或者Insert等操作没有反应时,很有可能是因为被操作的表被锁定,导致无法进行操作.这个时候需要解锁. 首先查看具体有哪些表被锁定 SELECT object_name, machine, s.sid, s.serial# FROM gv$locked_object l, dba_objects o, gv$session s WHERE l.object_id = o.object_id AND l.session_id = s.sid; 查询结果如下: 然

yum锁定强行解锁

Another app is currently holding the yum lock; waiting for it to exit...  The other application is: PackageKit    Memory : 153 M RSS (266 MB VSZ)    Started: Thu Jul 12 00:03:05 2012 - 06:19 ago State  : Sleeping, pid: 4018 解决方法: rm -rf /var/run/yum.