C#通过shell32来控制本地连接

 

ContractedBlock.gif ExpandedBlockStart.gif Code
//禁用 SetNetworkAdapter(False)
        
//启用 SetNetworkAdapter(True)

        
//添加引用system32\shell32.dll 
        private static bool SetNetworkAdapter(bool status) {
            
const string discVerb = "Disable"// "停用(&B)";
            const string connVerb = "Enable"// "启用(&A)";
            const string network = "Network Connections"//"网络连接";
            const string networkConnection = "Local Area Connection"// "本地连接"

            
string sVerb = null;

            
if (status) {
                sVerb 
= connVerb;
            } 
else {
                sVerb 
= discVerb;
            }

            Shell32.Shell sh 
= new Shell32.Shell();
            Shell32.Folder folder 
= sh.NameSpace(Shell32.ShellSpecialFolderConstants.ssfCONTROLS);

            
try {
                
//进入控制面板的所有选项 
                foreach (Shell32.FolderItem myItem in folder.Items()) {
                    
//进入网络连接 
                    if (myItem.Name == network) {
                        Shell32.Folder fd 
= (Shell32.Folder) myItem.GetFolder;
                        
foreach (Shell32.FolderItem fi in fd.Items()) {
                            
//找到本地连接 
                            if ((fi.Name == networkConnection)) {
                                
//找本地连接的所有右键功能菜单 
                                foreach (Shell32.FolderItemVerb Fib in fi.Verbs()) {
                                    
if (Fib.Name == sVerb) {
                                        Fib.DoIt();
                                        
return true;
                                    }
                                }
                            }
                        }
                    }
                }
            } 
catch (Exception e) {
                Console.WriteLine(e.Message);
                
return false;
            }
            
return true;
        }

 

转载于:https://www.cnblogs.com/rickiedu/archive/2009/06/23/1509639.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在使用C#连接本地Redis时,你可以使用ServiceStack.Redis客户端库来进行连接和操作。首先,在你的代码中引入相关的命名空间: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; 然后,在你的代码中创建一个RedisClient对象,指定Redis服务器的IP地址和端口号: public static ServiceStack.Redis.RedisClient client = new ServiceStack.Redis.RedisClient("127.0.0.1", 6379); 接下来,你可以使用RedisClient对象进行连接和操作。例如,你可以使用Get方法来读取数据: string name = client.Get<string>("name"); string pwd = client.Get<string>("password"); 你可以使用Set方法来存储数据: client.Set<string>("name1", username.Value); client.Set<string>("password1", userpwd.Value); 这样就可以将用户名和密码存储到Redis中了。 希望这可以帮到你!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [​C#操作redis​](https://blog.csdn.net/qq_45659882/article/details/121958035)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [C# 中Redis缓存的使用](https://blog.csdn.net/yicunyangguang/article/details/130981193)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值